5.6. Asynchronously executing a request
The steps to asynchronously execute a request are as follows. The algorithm takes a source object and an operation to perform on a database, and an optional request.
These steps can be aborted at any point if the transaction the created request belongs to is aborted using the steps to abort a transaction.
Let transaction be the transaction associated with source.
Assert: transaction is active.
If request was not given, let request be a new request with source as source.
Add request to the end of transaction’s request list.
Run these steps in parallel:
Wait until all previously added requests in transaction have their done flag set.
Let result be the result of performing operation.
If result is an error, then revert all changes made by operation.
This only reverts the changes done by this request, not any other changes made by the transaction.
Queue a task to run these steps:
Set the done flag on request.
If result is an error, then:
Set the result of request to undefined.
Set the error of request to result.
Fire an error event at request.
Otherwise:
Set the result of request to result.
Set the error of request to undefined.
Fire a success event at request.
Return request.