Resumable functions
Any function wrapped with dispatch.Func
becomes a resumable function.
This means that every function called via Await
method becomes a checkpoint in the execution of that function.
When an exception is raised, Dispatch will retry execution of the entire function from the last successful checkpoint.
For example, if function has three Await
calls and the last one raised an exception, the next time that function is executed, it will restore the return values of the first two Await
calls and will only re-run the third.
Consider this example application that implements a checkout flow. When user purchases a product, application charges the credit card, marks the order as completed and sends an email confirmation.
If sendEmailConfirmation
raises an exception, checkout
function will be executed again, but it won’t execute chargeCreditCard
again. Instead, Dispatch restores receiptId
from the previous execution and runs sendEmailConfirmation
right away. No need to worry about charging user’s credit card twice.
Dispatch makes checkout
function resumable, meaning that it picks up execution where it left off. This includes any other functions that checkout
calls, as long as they’re also wrapped with dispatch.Func
.
This powerful mechanism is so simple to integrate and yet it offers incredible value — Dispatch ensures that resumable functions always run to completion, no matter what failures it encounters.