pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:259:   class Promise   {    inherit Future;       //! The future value that we promise.    Future future()    {    return Future::this;    }    -  //! Fulfill the @[Future] value. -  void success(mixed value) +  protected void unlocked_success(mixed value)    { -  object key = mux->lock(); +     if (state < STATE_REJECTED) {    result = value;    state = STATE_FULFILLED;    function cb = success_cb;    array(mixed) extra = success_ctx;    cond->broadcast(); -  key = 0; +     if (cb) {    call_out(cb, 0, value, @extra);    }    }    }    -  //! Reject the @[Future] value. -  void failure(mixed value) +  //! Fulfill the @[Future] value. +  void success(mixed value)    {    object key = mux->lock(); -  +  unlocked_success(value); +  key = 0; +  } +  +  protected void unlocked_failure(mixed value) +  {    state = STATE_REJECTED;    result = value;    function cb = failure_cb;    array(mixed) extra = failure_ctx;    cond->broadcast(); -  key = 0; +     if (cb) {    call_out(cb, 0, value, @extra);    }    }    -  +  //! Reject the @[Future] value. +  void failure(mixed value) +  { +  object key = mux->lock(); +  unlocked_failure(value); +  key = 0; +  } +     protected void destroy()    {    if (!state) {    failure(({ "Promise broken.\n", backtrace() }));    }    }   }      protected class FirstCompleted   {