pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:29:   //! to be called directly, without using a backend.   //!   //! @note   //! As long as the backend hasn't started, it will default to @expr{false@}.   //! Upon startup of the backend, it will change to @expr{true@} unless you   //! explicitly called @[use_backend()] before that.   //!   //! @note   //! (Un)setting this typically alters the order in which some callbacks   //! are called (depending on what happens in a callback). + //! + //! @seealso + //! @[Future()->set_backend()], @[Future()->call_callback()]   final void use_backend(int enable)   {    callout = enable ? call_out : callnow;    remove_call_out(auto_use_backend);   }      private mixed    callnow(function(mixed ...:void) f, int|float delay, mixed ... args)   {    mixed err = catch (f(@args));
pike.git/lib/modules/Concurrent.pmod:73:   class Future   {    mixed result;    State state;       protected array(array(function(mixed, mixed ...: void)|mixed))    success_cbs = ({});    protected array(array(function(mixed, mixed ...: void)|mixed))    failure_cbs = ({});    +  protected Pike.Backend backend; +  +  //! Set the backend to use for calling any callbacks. +  //! +  //! @note +  //! This overides the mode set by @[use_backend()]. +  //! +  //! @seealso +  //! @[get_backend()], @[use_backend()] +  void set_backend(Pike.Backend backend) +  { +  this::backend = backend; +  } +  +  //! Get the backend (if any) used to call any callbacks. +  //! +  //! This returns the value set by @[set_backend()]. +  //! +  //! @seealso +  //! @[set_backend()] +  Pike.Backend get_backend() +  { +  return backend; +  } +     //! Call a callback function.    //!    //! @param cb    //! Callback function to call.    //!    //! @param args    //! Arguments to call @[cb] with. -  +  //! +  //! The default implementation calls @[cb] via the +  //! backend set via @[set_backend()] (if any), and +  //! otherwise falls back the the mode set by +  //! @[use_backend()]. +  //! +  //! @seealso +  //! @[set_backend()], @[use_backend()]    protected void call_callback(function cb, mixed ... args)    { -  +  if (backend) { +  backend->call_out(cb, 0, @args); +  } else {    callout(cb, 0, @args);    } -  +  }       //! Wait for fulfillment and return the value.    //!    //! @throws    //! Throws on rejection.    mixed get()    {    State s = state;    mixed res = result;    if (!s) {
pike.git/lib/modules/Concurrent.pmod:570:    return then(0, 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() })); +  (backend?backend->call_out:call_out) +  (p->try_failure, seconds, ({ "Timeout.\n", backtrace() }));    return p->future();    }       protected string _sprintf(int t)    {    return t=='O' && sprintf("%O(%s,%O)", this_program,    ([ STATE_PENDING : "pending",    STATE_REJECTED : "rejected",    STATE_FULFILLED : "fulfilled" ])[state],    result);