B2G/gecko/toolkit/content/Task.jsm
/**
   * Creates and starts a new task.
   *
   * @param aTask
   *        - If you specify a generator function, it is called with no
   *          arguments to retrieve the associated iterator.  The generator
   *          function is a task, that is can yield promise objects to wait
   *          upon.
   *        - If you specify the iterator returned by a generator function you
   *          called, the generator function is also executed as a task.  This
   *          allows you to call the function with arguments.
   *        - If you specify a function that is not a generator, it is called
   *          with no arguments, and its return value is used to resolve the
   *          returned promise.
   *        - If you specify anything else, you get a promise that is already
   *          resolved with the specified value.
   *
   * @return A promise object where you can register completion callbacks to be
   *         called when the task terminates.
   */
Creates and starts a new task.
@param aTask
- If you specify a generator function, it is called with no
arguments to retrieve the associated iterator.  The generator
function is a task, that is can yield promise objects to wait
upon.
- If you specify the iterator returned by a generator function you
called, the generator function is also executed as a task.  This
allows you to call the function with arguments.
- If you specify a function that is not a generator, it is called
with no arguments, and its return value is used to resolve the
returned promise.
- If you specify anything else, you get a promise that is already
resolved with the specified value.

@return A promise object where you can register completion callbacks to be
called when the task terminates.
Creates and starts a new task . @param aTask - If you specify a generator function it is called with no arguments to retrieve the associated iterator . The generator function is a task that is can yield promise objects to wait upon . - If you specify the iterator returned by a generator function you called the generator function is also executed as a task . This allows you to call the function with arguments . - If you specify a function that is not a generator it is called with no arguments and its return value is used to resolve the returned promise . - If you specify anything else you get a promise that is already resolved with the specified value . @return A promise object where you can register completion callbacks to be called when the task terminates .
function Task_spawn(aTask) {
    if (aTask && typeof(aTask) == "function") {
      aTask = aTask();
    }
    if (aTask && typeof(aTask.send) == "function") {
      return new TaskImpl(aTask).deferred.promise;
    }
    return Promise.resolve(aTask);
  }
function Task_spawn ( aTask ) { if ( aTask && typeof ( aTask ) == "function" ) { aTask = aTask ( ) ; } if ( aTask && typeof ( aTask . send ) == "function" ) { return new TaskImpl ( aTask ) . deferred . promise ; } return Promise . resolve ( aTask ) ; }
Creates and starts a new task.
Creates and starts a new task .
// Let's call into the function ourselves. // This is an iterator resulting from calling a generator function. // Just propagate the given value to the caller as a resolved promise.