diff --git a/CHANGELOG.md b/CHANGELOG.md index 617ae1f..ca9bbb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - `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. -------------------------------------------------------------------------------- diff --git a/docs/api/reactivity-utility.md b/docs/api/reactivity-utility.md index d084976..b8bff4d 100644 --- a/docs/api/reactivity-utility.md +++ b/docs/api/reactivity-utility.md @@ -7,7 +7,7 @@ Queues a callback to run when a scope is reran or destroyed. - **Type** ```luau - function cleanup(v: Function | Disconnectable | Destroyable) + function cleanup(v: Function | Disconnectable | Destroyable | thread) type Function = () -> () type Destroyable = { destroy: () -> () } diff --git a/src/cleanup.luau b/src/cleanup.luau index 54195fb..20d188b 100644 --- a/src/cleanup.luau +++ b/src/cleanup.luau @@ -8,6 +8,7 @@ local push_cleanup = graph.push_cleanup local function helper(obj: any) return 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 obj.destroy then function() obj:destroy() end elseif obj.disconnect then function() obj:disconnect() end @@ -35,6 +36,7 @@ type Disconnectable = { disconnect: (any) -> () } | { Disconnect: (any) -> () } return cleanup :: ( (callback: () -> ()) -> () ) & + ( (thread: thread) -> () ) & ( (instance: Destroyable) -> () ) & ( (connection: Disconnectable) -> () ) & ( (instance: Instance) -> () ) &