Skip to content

useCleanup 0.1.0 view source

function useCleanup<Tasks...>(
  scope: Fusion.Scope,
  ...: Tasks...
): Tasks...

Add clean up tasks to the scope. Returns the clean up tasks, allowing it to be used in declarations.


Parameters

scope : Fusion.Scope

The scope to store cleanup tasks.

... : Tasks...

The tasks to be added.


Returns -> Tasks...

The tasks that has been added.


Example Usage

local timeElapsed = scope:Value(0)
local connection = scope:useCleanup(
  RunService.PostSimulation:Connect(function(dt)
    timeElapsed:set(peek(timeElapsed) + dt)
  end)
)

task.wait(5)
connection:Disconnect()
print(`Took around {peek(timeElapsed)} seconds`)