Chain together multiple Promise-returning functions, and only handle a potential error once. If any function rejects in the chain, execution will jump down to `catch`.
```lua
doSomething()
:andThen(doSomethingElse)
:andThen(doSomethingOtherThanThat)
:andThen(doSomethingAgain)
:catch(print)
```
## IsInGroup wrapper
This function demonstrates how to convert a function that yields into a function that returns a Promise. (Assuming you don't want to use <ApiLinkto="Promise.promisify"/>)
local tween = TweenService:Create(obj, tweenInfo, props)
if onCancel(function()
tween:Cancel()
end) then return end
tween.Completed:Connect(resolve)
tween:Play()
end)
end
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 <ApiLinkto="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 `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.