pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:276:    return results(({ this_program::this }) + others);    }       //! 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->maybe_failure, seconds, ({ "Timeout.\n", backtrace() })); +  call_out(p->try_failure, seconds, ({ "Timeout.\n", backtrace() }));    return p->future();    }   }      //! Promise to provide a @[Future] value.   //!   //! Objects of this class are typically kept internal to the   //! code that provides the @[Future] value. The only thing   //! that is directly returned to the user is the return   //! value from @[future()].
pike.git/lib/modules/Concurrent.pmod:321:    }    }    }    }       //! Fulfill the @[Future].    //!    //! @param value    //! Result of the @[Future].    //! -  //! Mark the @[Future] as fulfilled if it hasn't already been failed, -  //! and schedule the @[on_success()] callbacks to be called as soon -  //! as possible. +  //! @throws +  //! Throws an error if the @[Future] already has been fulfilled +  //! or failed.    //! -  +  //! Mark the @[Future] as fulfilled, and schedule the @[on_success()] +  //! callbacks to be called as soon as possible. +  //!    //! @seealso -  //! @[maybe_failure()], @[failure()], @[on_success()] +  //! @[try_success()], @[try_failure()], @[failure()], @[on_success()]    void success(mixed value)    { -  +  if (state) error("Promise has already been finalized.\n");    object key = mux->lock(); -  +  if (state) error("Promise has already been finalized.\n");    unlocked_success(value);    key = 0;    }    -  +  //! Fulfill the @[Future] if it hasn't been fulfilled or failed already. +  //! +  //! @param value +  //! Result of the @[Future]. +  //! +  //! Mark the @[Future] as fulfilled if it hasn't already been fulfilled +  //! or failed, and in that case schedule the @[on_success()] callbacks +  //! to be called as soon as possible. +  //! +  //! @seealso +  //! @[success()], @[try_failure()], @[failure()], @[on_success()] +  void try_success(mixed value) +  { +  if (state) return; +  object key = mux->lock(); +  if (state) return; +  unlocked_success(value); +  key = 0; +  } +     protected void unlocked_failure(mixed value)    {    state = STATE_REJECTED;    result = value;    cond->broadcast();    foreach(failure_cbs,    [function(mixed, mixed ...: void) cb,    array(mixed) extra]) {    if (cb) {    call_out(cb, 0, value, @extra);    }    }    }       //! Reject the @[Future] value.    //!    //! @param value    //! Failure result of the @[Future].    //! -  +  //! @throws +  //! Throws an error if the @[Future] already has been fulfilled +  //! or failed. +  //!    //! Mark the @[Future] as failed, and schedule the @[on_failure()]    //! callbacks to be called as soon as possible.    //!    //! @seealso -  //! @[maybe_failure()], @[success()], @[on_failure()] +  //! @[try_failure()], @[success()], @[on_failure()]    void failure(mixed value)    { -  +  if (state) error("Promise has already been finalized.\n");    object key = mux->lock(); -  +  if (state) error("Promise has already been finalized.\n");    unlocked_failure(value);    key = 0;    }       //! Maybe reject the @[Future] value.    //!    //! @param value    //! Failure result of the @[Future].    //!    //! Mark the @[Future] as failed if it hasn't already been fulfilled, -  //! and schedule the @[on_failure()] callbacks to be called as soon -  //! as possible. +  //! and in that case schedule the @[on_failure()] callbacks to be +  //! called as soon as possible.    //!    //! @seealso    //! @[failure()], @[success()], @[on_failure()] -  void maybe_failure(mixed value) +  void try_failure(mixed value)    { -  +  if (state) return;    object key = mux->lock();    if (state) return;    unlocked_failure(value);    }       protected void destroy()    {    if (!state) {    unlocked_failure(({ "Promise broken.\n", backtrace() }));    }
pike.git/lib/modules/Concurrent.pmod:401:   protected class FirstCompleted   {    inherit Promise;       protected void create(array(Future) futures)    {    if (!sizeof(futures)) {    state = STATE_FULFILLED;    return;    } -  futures->on_failure(got_failure); -  futures->on_success(got_success); +  futures->on_failure(try_failure); +  futures->on_success(try_success);    } -  -  protected void got_failure(mixed err) -  { -  if (state) return; -  failure(err); +    }    -  protected void got_success(mixed val) -  { -  if (state) return; -  success(val); -  } - } -  +    //! Return a @[Future] that represents the first   //! of the @[futures] that completes.   Future first_completed(array(Future) futures)   {    Promise p = FirstCompleted(futures);    return p->future();   }      protected class Results   {