Bug 1517456 - Sqlite.jsm's executeTransaction no longer needs to handle generator functions. r=mak
authorMark Banner <standard8@mozilla.com>
Fri, 04 Jan 2019 08:41:35 +0000
changeset 509622 d11632d4bde430996964c3599d4d878832ed6aaa
parent 509621 348ab7a8ab4dca7674d061341fb29cbfe43b2cd9
child 509623 f26ec01f436a9ac376be18b3be41c03de7812c7b
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1517456
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517456 - Sqlite.jsm's executeTransaction no longer needs to handle generator functions. r=mak Differential Revision: https://phabricator.services.mozilla.com/D15645
toolkit/modules/Sqlite.jsm
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -17,17 +17,16 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Timer.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
   Services: "resource://gre/modules/Services.jsm",
   OS: "resource://gre/modules/osfile.jsm",
   Log: "resource://gre/modules/Log.jsm",
   FileUtils: "resource://gre/modules/FileUtils.jsm",
-  Task: "resource://gre/modules/Task.jsm",
   PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
 });
 
 XPCOMUtils.defineLazyServiceGetter(this, "FinalizationWitnessService",
                                    "@mozilla.org/toolkit/finalizationwitness;1",
                                    "nsIFinalizationWitnessService");
 
 // Regular expression used by isInvalidBoundLikeQuery
@@ -297,24 +296,24 @@ ConnectionData.prototype = Object.freeze
    * or even an individual operation, can still be pending when the process shuts
    * down. If any of this operations is a write, this can cause data loss, simply
    * because the write has not been completed (or even started) by shutdown.
    *
    * To avoid this risk, clients are encouraged to use `executeBeforeShutdown` for
    * any write operation, as follows:
    *
    * myConnection.executeBeforeShutdown("Bookmarks: Removing a bookmark",
-   *   Task.async(function*(db) {
+   *   async function(db) {
    *     // The connection will not be closed and shutdown will not proceed
    *     // until this task has completed.
    *
    *     // `db` exposes the same API as `myConnection` but provides additional
    *     // logging support to help debug hard-to-catch shutdown timeouts.
    *
-   *     yield db.execute(...);
+   *     await db.execute(...);
    * }));
    *
    * @param {string} name A human-readable name for the ongoing operation, used
    *  for logging and debugging purposes.
    * @param {function(db)} task A function that takes as argument a Sqlite.jsm
    *  db and returns a Promise.
    */
   executeBeforeShutdown(parent, name, task) {
@@ -594,23 +593,17 @@ ConnectionData.prototype = Object.freeze
             } else {
               this._log.warn("A transaction was already in progress, likely a nested transaction", ex);
               throw ex;
             }
           }
 
           let result;
           try {
-            // Keep Task.spawn here to preserve API compat; unfortunately
-            // func was a generator rather than a task here.
-            result = func();
-            if (Object.prototype.toString.call(result) == "[object Generator]")
-              result = await Task.spawn(func); // eslint-disable-line mozilla/no-task
-            else
-              result = await result;
+            result = await func();
           } catch (ex) {
             // It's possible that the exception has been caused by trying to
             // close the connection in the middle of a transaction.
             if (this._closeRequested) {
               this._log.warn("Connection closed while performing a transaction", ex);
             } else {
               this._log.warn("Error during transaction. Rolling back", ex);
               // If we began a transaction, we must rollback it.
@@ -1401,32 +1394,31 @@ OpenedConnection.prototype = Object.free
 
   /**
    * Perform a transaction.
    *
    * *****************************************************************************
    * YOU SHOULD _NEVER_ NEST executeTransaction CALLS FOR ANY REASON, NOR
    * DIRECTLY, NOR THROUGH OTHER PROMISES.
    * FOR EXAMPLE, NEVER DO SOMETHING LIKE:
-   *   yield executeTransaction(function* () {
+   *   await executeTransaction(async function () {
    *     ...some_code...
-   *     yield executeTransaction(function* () { // WRONG!
+   *     await executeTransaction(async function () { // WRONG!
    *       ...some_code...
    *     })
-   *     yield someCodeThatExecuteTransaction(); // WRONG!
-   *     yield neverResolvedPromise; // WRONG!
+   *     await someCodeThatExecuteTransaction(); // WRONG!
+   *     await neverResolvedPromise; // WRONG!
    *   });
    * NESTING CALLS WILL BLOCK ANY FUTURE TRANSACTION UNTIL A TIMEOUT KICKS IN.
    * *****************************************************************************
    *
-   * A transaction is specified by a user-supplied function that is a
-   * generator function which can be used by Task.jsm's Task.spawn(). The
-   * function receives this connection instance as its argument.
+   * A transaction is specified by a user-supplied function that is an
+   * async function. The function receives this connection instance as its argument.
    *
-   * The supplied function is expected to yield promises. These are often
+   * The supplied function is expected to return promises. These are often
    * promises created by calling `execute` and `executeCached`. If the
    * generator is exhausted without any errors being thrown, the
    * transaction is committed. If an error occurs, the transaction is
    * rolled back.
    *
    * The returned value from this function is a promise that will be resolved
    * once the transaction has been committed or rolled back. The promise will
    * be resolved to whatever value the supplied function resolves to. If