pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:272:    //! by the fulfilled results of @[others].    //!    //! @seealso    //! @[results()]    this_program zip(this_program ... others)    {    if (!sizeof(others)) return this_program::this;    return results(({ this_program::this }) + others);    }    +  //! JavaScript Promise API close but not identical equivalent +  //! of @[transform()]. +  //!    //! @param onfulfilled    //! Function to be called on fulfillment. The first argument will be the    //! result of @b{this@} @[Future].    //! The return value will be the result of the new @[Future].    //!    //! @param onrejected    //! Function to be called on failure. The first argument will be the    //! failure result of @b{this@} @[Future].    //! The return value will be the failure result of the new @[Future].    //!    //! @param extra    //! Any extra context needed for @expr{onfulfilled@} and    //! @expr{onrejected@}. They will be provided    //! as arguments two and onwards when the callbacks are called.    //!    //! @returns    //! The new @[Future].    //!    //! @seealso -  //! @[thencatch()] +  //! @[transform()], @[thencatch()]    //! @[on_success()], @[Promise.success()]    //! @[on_failure()], @[Promise.failure()]    //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@} -  this_program then(void|function(mixed, mixed ... : mixed) onfulfilled, +  inline this_program then(void|function(mixed, mixed ... : mixed) onfulfilled,    void|function(mixed, mixed ... : mixed) onrejected, -  mixed ... extra) -  { +  mixed ... extra) {    Promise p = Promise(); -  void wrapsuccess() { -  p->success(onfulfilled(result, @extra)); -  } -  void wrapfailure() { -  p->failure(onrejected(result, @extra)); -  } -  on_success(onfulfilled ? wrapsuccess : p->success); -  on_failure(onrejected ? wrapfailure : p->failure); +  if (onfulfilled) +  on_success(apply, p, onfulfilled, extra); +  else +  on_success(p->success); +  if (onrejected) +  on_failure(apply, p, onrejected, extra); +  else +  on_failure(p->failure);    return p->future();    }    -  +  //! JavaScript Promise API equivalent of @[recover()]. +  //!    //! @param onrejected    //! Function to be called. The first argument will be the    //! failure result of @b{this@} @[Future].    //! The return value will the failure result of the new @[Future].    //!    //! @param extra    //! Any extra context needed for    //! @expr{onrejected@}. They will be provided    //! as arguments two and onwards when the callback is called.    //!    //! @returns    //! The new @[Future].    //!    //! @seealso -  //! @[then()], @[on_failure()], @[Promise.failure()] +  //! @[recover()], @[then()], @[on_failure()], @[Promise.failure()]    //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@} -  this_program thencatch(function(mixed, mixed ... : mixed) onrejected, +  inline this_program thencatch(function(mixed, mixed ... : mixed) onrejected,    mixed ... extra) { -  return then(0, onrejected, @extra); +  return recover(onrejected, @extra);    }       //! Return a @[Future] that will either be fulfilled with the fulfilled    //! result of this @[Future], or be failed after @[seconds] have expired.    this_program timeout(int|float seconds)    {    Promise p = Promise();    on_failure(p->failure);    on_success(p->success);    call_out(p->try_failure, seconds, ({ "Timeout.\n", backtrace() }));
pike.git/lib/modules/Concurrent.pmod:513:   //! of the @expr{futures@} that completes.   //!   //! @seealso   //! @[race()]   Future first_completed(array(Future) futures)   {    Promise p = FirstCompleted(futures);    return p->future();   }    - //! JavaScript Promise API equivalent of @[first_completed]. + //! JavaScript Promise API equivalent of @[first_completed()].   //!   //! @seealso   //! @[first_completed()]   //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@}   inline Future race(array(Future) futures)   {    return first_completed(futures);   }      protected class Results
pike.git/lib/modules/Concurrent.pmod:576:   {    Promise p = Results(futures);    return p->future();   }      //! JavaScript Promise API equivalent of @[results()].   //!   //! @seealso   //! @[results()]   //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@} - inline Future all(array(Future) futures) + inline variant Future all(array(Future) futures)   {    return results(futures);   } -  + inline variant Future all(Future ... futures) + { +  return results(futures); + }      //! @returns   //! A new @[Future] that has already failed for the specified @expr{reason@}.   //!   //! @seealso   //! @[Future.on_failure()], @[Promise.failure()]   //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@}   Future reject(mixed reason)   {    object p = Promise();    p->failure(reason);    return p;   }      //! @returns   //! A new @[Future] that has already been fulfilled with @expr{value@}   //! as result. If @expr{value@} is an object which already - //! has @[failure] and @[success] methods, return it unchanged. + //! has @[on_failure] and @[on_success] methods, return it unchanged.   //!   //! @note   //! This function can be used to ensure values are futures.   //!   //! @seealso   //! @[Future.on_success()], @[Promise.success()]   //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@}   Future resolve(mixed value)   { -  if (objectp(value) && functionp(value->failure) && functionp(value->success)) +  if (objectp(value) && value->on_failure && value->on_success)    return value;    object p = Promise();    p->success(value);    return p;   }      //! Return a @[Future] that represents the array of mapping @[fun]   //! over the results of the completed @[futures].   Future traverse(array(Future) futures,    function(mixed, mixed ... : mixed) fun,