This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
Release v0.0.19-alpha
- New Signal implementation
- Remove Thread module in favor of new
task.spawn
andtask.defer
functions - Add Janitor / Remove Maid
- Add Timer module
MIGRATION FROM v18 TO v19:
- Remove
require
s ofThread
module - Replace
require
s ofMaid
withJanitor
Thread.Spawn
->task.defer
Thread.SpawnNow
->task.spawn
Thread.Delay
->task.delay
Thread.DelayRepeat
-> UseTimer
class (see below)maid:GiveTask
->janitor:Add
maid:GivePromise
->janitor:AddPromise
maid:DoCleaning
->janitor:Cleanup
maid[id] = nil
->janitor:Remove(id)
Timer class:
The Timer class makes it easy to schedule functions at certain intervals.
local Timer = require(Knit.Util.Timer)
local timer = Timer.new(1)
timer.Tick:Connect(function()
print("Tock")
end)
timer:Start()
...
timer:Stop()
...
timer:Destroy()
Janitor class:
For the most part, swapping out Janitor for Maid should be quite seamless, as their APIs are nearly identical, besides some name changes. It is worth noting some significant changes:
- Instead of clearing an item from a maid using
maid[id] = nil
, Janitor has a dedicatedRemove
method, in which you pass in the ID that you explicitly gave it onAdd
. For instance:janitor:Add(item, nil, "SomeID"); janitor:Remove("SomeID")
. - Janitor comes with a
LinkToInstance
, which lets you link the janitor instance to the life of a Roblox instance. If that instance is deparented, the janitor will be cleaned up. - The
Add
method's 2nd parameter is an optional cleanup method name, which can be used if your object's cleanup method is different than Destroy.
Removal of Thread module:
With the addition of the built-in task
library, the Thread module is obsolete.
- Use
task.spawn
to spawn a thread immediately (same behavior asThread.SpawnNow
). - Use
task.defer
to schedule a thread to run using the internal deferral scheduling (still within the same frame). This is roughly a replacement forThread.Spawn
. If you still want to delay a frame, simply usetask.delay(0, function() ... end)
. - Use
task.delay
to schedule a thread to run after some period of time. - Use
Timer
class instead ofThread.DelayRepeat
.
Snippets:
If you use the VS Code snippets provided from the documentation, be sure to update them to use Janitor instead of Maid.