Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Release v0.0.19-alpha

Compare
Choose a tag to compare
@github-actions github-actions released this 03 Aug 23:43
a50c86e
  • New Signal implementation
  • Remove Thread module in favor of new task.spawn and task.defer functions
  • Add Janitor / Remove Maid
  • Add Timer module

MIGRATION FROM v18 TO v19:

  • Remove requires of Thread module
  • Replace requires of Maid with Janitor
  • Thread.Spawn -> task.defer
  • Thread.SpawnNow -> task.spawn
  • Thread.Delay -> task.delay
  • Thread.DelayRepeat -> Use Timer 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 dedicated Remove method, in which you pass in the ID that you explicitly gave it on Add. 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 as Thread.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 for Thread.Spawn. If you still want to delay a frame, simply use task.delay(0, function() ... end).
  • Use task.delay to schedule a thread to run after some period of time.
  • Use Timer class instead of Thread.DelayRepeat.

Snippets:
If you use the VS Code snippets provided from the documentation, be sure to update them to use Janitor instead of Maid.