A tree-based thread lifecycle library which sits on top of the Roblox task library.
localfunctionAnimate(Item, Damping, Frequency, Properties)
-- ...endlocalTestAnimation=Async.Spawn(function()
localfunctionInitialState()
Animate(Workspace.Part1, 1, 5, {
Position=Vector3.new(0, 10, 0);
})
Animate(Workspace.Part2, 1, 100, {
Position=Vector3.new(0, 10, 0);
})
endAsync.OnFinish(InitialState)
InitialState()
localfunctionAnimatePart1()
forStep=1, 3doAnimate(Workspace.Part1, 1, 5, {
Position=Vector3.new(0, 10+10*Step, 0);
})
task.wait(1)
endendlocalfunctionAnimatePart2()
forStep=1, 3doAnimate(Workspace.Part2, 1, 100, {
Position=Vector3.new(0, 10+10*Step, 0);
})
task.wait(1)
endendtask.wait(1) -- 1 sec delay before animation startsAsync.Spawn(AnimatePart1)
Async.Spawn(AnimatePart2)
end)
task.wait(2)
-- This will not only cancel the animation thread, but also the sub-threads-- which the animation thread spawned (AnimatePart1, AnimatePart2). When-- cancelled, it will call OnFinish, and reset the animation to the initial-- state (InitialState).Async.Cancel(TestAnimation)localSuccess, Result=Async.Await(Async.Spawn(function()
localValue=math.random()
task.wait(2)
if (Value>0.5) thenreturnValueenderror("<FAIL_TAG>") -- Surrounding alphanumeric + underscore with < & > will capture the tag in the error message without all the mess.end))
print(Success, Result)print(Async.AwaitAll({
Async.Spawn(function()
task.wait(1)
return"Delayed"end);
Async.Spawn(function()
return"Immediate"end);
}))
--> {{true, "Immediate"}, {true, "Delayed"}}print(Async.AwaitFirst({
Async.Spawn(function()
task.wait(1)
return"Last"end);
Async.Spawn(function()
return"First"end);
}))
--> true, "First"localCharacters= {}
localStop=Async.Timer(1, function()
table.clear(Characters)
for_, Playeringame.Players:GetChildren() dolocalChar=Player.Characterif (notChar) thenreturnendtable.insert(Characters, Char)
endend, "FindPlayers")
-- "FindPlayers" will show up in the Microprofiler, though always ensure the timer does not block if the tag is specifiedAsync.Delay(5, Stop)