mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Update done docs
This commit is contained in:
parent
de4a43d32e
commit
4daaf7ee5d
2 changed files with 15 additions and 10 deletions
|
@ -52,9 +52,9 @@ end
|
|||
## Cancellable animation sequence
|
||||
The following is an example of an animation sequence which is composable and cancellable. If the sequence is cancelled, the animated part will instantly jump to the end position as if it had played all the way through.
|
||||
|
||||
We use <ApiLink to="Promise.finallyCall" />, which uses `finally` internally, instead of `andThen` because we want the Promises to run even if the Promise is cancelled. We handle the case of the Promise being cancelled with the `onCancel` function.
|
||||
We use <ApiLink to="Promise.doneCall" />, which uses `done` internally, instead of `andThen` because we want the Promises to run even if the Promise is cancelled. We handle the case of the Promise being cancelled with the `onCancel` function.
|
||||
|
||||
We take advantage of Promise chaining by returning Promises from the `finally` handler functions. Because of this behavior, cancelling the final Promise in the chain will propagate up to the very top and cancel every single Promise you see here.
|
||||
We take advantage of Promise chaining by returning Promises from the `done` handler functions. Because of this behavior, cancelling the final Promise in the chain will propagate up to the very top and cancel every single Promise you see here.
|
||||
|
||||
```lua
|
||||
local Promise = require(game.ReplicatedStorage.Promise)
|
||||
|
@ -84,13 +84,13 @@ end
|
|||
|
||||
local function runAnimation(part, intensity)
|
||||
return Promise.resolve()
|
||||
:finallyCall(sleep, 1))
|
||||
:finallyCall(runTween, part, {
|
||||
:doneCall(sleep, 1)
|
||||
:doneCall(runTween, part, {
|
||||
Reflectance = 1 * intensity
|
||||
}):finallyCall(runTween, part, {
|
||||
}):doneCall(runTween, part, {
|
||||
CFrame = CFrame.new(part.Position) *
|
||||
CFrame.Angles(0, math.rad(90 * intensity), 0)
|
||||
}):finallyCall(runTween, part, {
|
||||
}):doneCall(runTween, part, {
|
||||
Size = (
|
||||
Vector3.new(10, 10, 10) * intensity
|
||||
) + Vector3.new(1, 1, 1)
|
||||
|
@ -98,9 +98,10 @@ local function runAnimation(part, intensity)
|
|||
end
|
||||
|
||||
local animation = Promise.resolve() -- Begin Promise chain
|
||||
:finallyCall(runAnimation, workspace.Part, 1)
|
||||
:finallyCall(sleep, 1)
|
||||
:finallyCall(runAnimation, workspace.Part, 0)
|
||||
:doneCall(runAnimation, workspace.Part, 1)
|
||||
:doneCall(sleep, 1)
|
||||
:doneCall(runAnimation, workspace.Part, 0)
|
||||
:catch(warn)
|
||||
|
||||
wait(2)
|
||||
animation:cancel() -- Remove this line to see the full animation
|
||||
|
|
|
@ -366,8 +366,12 @@ docs:
|
|||
desc: |
|
||||
Set a handler that will be called only if the Promise resolves or is cancelled. This method is similar to `finally`, except it doesn't catch rejections.
|
||||
|
||||
::: tip
|
||||
`done` should be reserved specifically when you want to perform some operation after the Promise is finished (like `finally`), but you don't want to consume rejections (like in <a href="/roblox-lua-promise/lib/Examples.html#cancellable-animation-sequence">this example</a>). You should use `andThen` instead if you only care about the Resolved case.
|
||||
:::
|
||||
|
||||
::: warning
|
||||
If this Promise is cancelled, any Promises chained off of it with `andThen` won't run. Only Promises chained with `done` and `finally` will run in the case of cancellation.
|
||||
Like `finally`, if the Promise is cancelled, any Promises chained off of it with `andThen` won't run. Only Promises chained with `done` and `finally` will run in the case of cancellation.
|
||||
:::
|
||||
|
||||
Returns a new promise chained from this promise.
|
||||
|
|
Loading…
Reference in a new issue