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.

  1. Let transaction be the transaction associated with source.

  2. Assert: transaction’s state is active.

  3. If request was not given, let request be a new request with source as source.

  4. Add request to the end of transaction’s request list.

  5. Run these steps in parallel:

    1. Wait until request is the first item in transaction’s request list that is not processed.

    2. Let result be the result of performing operation.

    3. If result is an error and transaction’s state is committing, then run abort a transaction with transaction and error, and terminate these steps.

    4. 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.

    5. Set request’s processed flag to true.

    6. Queue a task to run these steps:

      1. Remove request from transaction’s request list.

      2. Set request’s done flag to true.

      3. If result is an error, then:

        1. Set request’s result to undefined.

        2. Set request’s error to result.

        3. Fire an error event at request.

      4. Otherwise:

        1. Set request’s result to result.

        2. Set request’s error to undefined.

        3. Fire a success event at request.

  6. Return request.