Bucket
Used for cleanup of various data types and instances.
Functions
new
Creates a new bucket instance.
local BucketInstance = Bucket.new()
BucketInstance:Add(...)
BucketInstance:Remove(...)
BucketInstance:Destroy()
Add
Bucket:Add(Object: any,--
The object to be cleaned up
CleanupMethodName: string?--
If you're passing a table, this is an optional setting to choose the cleanup function name (defaults to Destroy or Disconnect)
) → any--
The object you inputted
Adds userdata or an instance to the bucket. Supported types include: Instance, RBXScriptConnection, function, thread, or table.
local BucketInstance = Bucket.new()
BucketInstance:Add(workspace.Baseplate)
BucketInstance:Add(RunService.RenderStepped:Connect(function()
-- ...
end))
BucketInstance:Add(function()
-- ...
end)
AddPromise
Bucket:AddPromise(Object: Promise--
The promise to be cleaned up
) → Promise--
The same promise that was inputted
Adds a promise to the bucket. Will return the promise, meaning it can be chained.
-- local MyPromise = ...
local BucketInstance = Bucket.new()
BucketInstance:AddPromise(MyPromise)
AttachToInstance
Tells the Bucket to destroy itself when the inputted instance is destroyed or parented to nil.
local BucketInstance = Bucket.new()
BucketInstance:AttachToInstance(PartInstance)
Extend
Creates another Bucket and adds it to this (the parent) one.
local BucketInstance = Bucket.new()
local SubBucketInstance = BucketInstance:Extend()
Remove
Bucket:Remove(Object: any--
The object to be removed from cleanup
) → ()Removes an object from Bucket's cleanup.
local BucketInstance = Bucket.new()
BucketInstance:Add(Value)
BucketInstance:Remove(Value) -- No longer cleaned up
GetWrappedDestroy
Bucket:GetWrappedDestroy() → () → nilReturns a function that, when called, destroys the Bucket.
local BucketInstance = Bucket.new()
local Destroy = BucketInstance:GetWrappedDestroy()
Destroy()
Destroy
Bucket:Destroy() → ()Destroys the Bucket, cleaning up all objects and promises inside of it.
local BucketInstance = Bucket.new()
-- Add stuff...
BucketInstance:Destroy()