5.6. Asynchronously executing a request
To asynchronously execute a request with the source object and an operation to perform on a database, and an optional request, run these steps:
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.
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 request is the first item in transaction’s request list that is not processed.
Let result be the result of performing operation.
If result is an error and transaction’s state is committing, then run abort a transaction with transaction and error, and terminate these steps.
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.
Set request’s processed flag to true.
Queue a task to run these steps:
Remove request from transaction’s request list.
Set request’s done flag to true.
If result is an error, then:
Set request’s result to undefined.
Set request’s error to result.
Fire an error event at request.
Otherwise:
Set request’s result to result.
Set request’s error to undefined.
Fire a success event at request.
Return request.