mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add thread cleanup helper
This commit is contained in:
parent
e60aa57ca2
commit
caa9eaf733
3 changed files with 9 additions and 1 deletions
|
|
@ -11,6 +11,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `create("ClassName", { props })` and `create(Instance, { props })` syntax.
|
- `create("ClassName", { props })` and `create(Instance, { props })` syntax.
|
||||||
|
- `cleanup()` now accepts `thread` types.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- A scope can no longer be destroyed while it is active. Strict mode will check
|
||||||
|
for this.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ Queues a callback to run when a scope is reran or destroyed.
|
||||||
- **Type**
|
- **Type**
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
function cleanup(v: Function | Disconnectable | Destroyable)
|
function cleanup(v: Function | Disconnectable | Destroyable | thread)
|
||||||
|
|
||||||
type Function = () -> ()
|
type Function = () -> ()
|
||||||
type Destroyable = { destroy: () -> () }
|
type Destroyable = { destroy: () -> () }
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ local push_cleanup = graph.push_cleanup
|
||||||
local function helper(obj: any)
|
local function helper(obj: any)
|
||||||
return
|
return
|
||||||
if typeof(obj) == "RBXScriptConnection" then function() obj:Disconnect() end
|
if typeof(obj) == "RBXScriptConnection" then function() obj:Disconnect() end
|
||||||
|
elseif type(obj) == "thread" then function() task.cancel(obj) end
|
||||||
elseif typeof(obj) == "Instance" then function() obj:Destroy() end
|
elseif typeof(obj) == "Instance" then function() obj:Destroy() end
|
||||||
elseif obj.destroy then function() obj:destroy() end
|
elseif obj.destroy then function() obj:destroy() end
|
||||||
elseif obj.disconnect then function() obj:disconnect() end
|
elseif obj.disconnect then function() obj:disconnect() end
|
||||||
|
|
@ -35,6 +36,7 @@ type Disconnectable = { disconnect: (any) -> () } | { Disconnect: (any) -> () }
|
||||||
|
|
||||||
return cleanup ::
|
return cleanup ::
|
||||||
( (callback: () -> ()) -> () ) &
|
( (callback: () -> ()) -> () ) &
|
||||||
|
( (thread: thread) -> () ) &
|
||||||
( (instance: Destroyable) -> () ) &
|
( (instance: Destroyable) -> () ) &
|
||||||
( (connection: Disconnectable) -> () ) &
|
( (connection: Disconnectable) -> () ) &
|
||||||
( (instance: Instance) -> () ) &
|
( (instance: Instance) -> () ) &
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue