Make root() return destructor automatically

This commit is contained in:
aaron 2024-10-06 15:37:05 +01:00
parent 8142acd1c1
commit 82eec61c45
8 changed files with 26 additions and 30 deletions

View file

@ -14,18 +14,15 @@ Creates and runs a function in a new stable scope.
- **Type**
```lua
function root<T...>(fn: (destroy: () -> ()) -> T...): T...
function root<T...>(fn: (() -> ()) -> T...): (() -> (), T...)
```
- **Details**
Returns the result of the given function.
Returns a function to destroy the root scope. Also passes this function as
the first argument into its callback.
Creates a new stable scope, where creation of effects can be tracked and
properly disposed of.
A function to destroy the root is passed into the callback, which will run
any cleanups and allow derived sources created to garbage collect.
All values returned by the callback are also returned following the destructor.
## source()