pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:113:    //!    //! This returns the value set by @[set_backend()].    //!    //! @seealso    //! @[set_backend()]    Pike.Backend get_backend()    {    return backend;    }    +  //! Create a new @[Promise] with the same base settings +  //! as the current object. +  //! +  //! Overload this function if you need to propagate more state +  //! to new @[Promise] objects. +  //! +  //! The default implementation copies the backend +  //! setting set with @[set_backend()] to the new @[Promise]. +  //! +  //! @seealso +  //! @[Promise], @[set_backend()] +  Promise promise_factory() +  { +  Promise res = Promise(); +  +  if (backend) { +  res->set_backend(backend); +  } +  +  return res; +  } +     //! 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
pike.git/lib/modules/Concurrent.pmod:316:    //! The new @[Future].    //!    //! @note    //! This method is used if your @[fun] returns a regular value (i.e.    //! @b{not@} a @[Future]).    //!    //! @seealso    //! @[map_with()], @[transform()], @[recover()]    this_program map(function(mixed, mixed ... : mixed) fun, mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_failure(p->failure);    on_success(apply, p, fun, extra);    return p->future();    }       //! This specifies a callback that is only called on success, and    //! allows you to alter the future.    //!    //! @param fun    //! Function to be called. The first argument will be the
pike.git/lib/modules/Concurrent.pmod:347:    //! The new @[Future].    //!    //! @note    //! This method is used if your @[fun] returns a @[Future] again.    //!    //! @seealso    //! @[map()], @[transform_with()], @[recover_with()], @[flat_map]    this_program map_with(function(mixed, mixed ... : this_program) fun,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_failure(p->failure);    on_success(apply_flat, p, fun, extra);    return p->future();    }       //! This is an alias for @[map_with()].    //!    //! @seealso    //! @[map_with()]    inline this_program flat_map(function(mixed, mixed ... : this_program) fun,
pike.git/lib/modules/Concurrent.pmod:388:    //!    //! @note    //! This method is used if your callbacks return a regular value (i.e.    //! @b{not@} a @[Future]).    //!    //! @seealso    //! @[recover_with()], @[map()], @[transform()]    this_program recover(function(mixed, mixed ... : mixed) fun,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_success(p->success);    on_failure(apply, p, fun, extra);    return p->future();    }       //! This specifies a callback that is only called on failure, and    //! allows you to alter the future into a success.    //!    //! @param fun    //! Function to be called. The first argument will be the
pike.git/lib/modules/Concurrent.pmod:419:    //! The new @[Future].    //!    //! @note    //! This method is used if your callbacks return a @[Future] again.    //!    //! @seealso    //! @[recover()], @[map_with()], @[transform_with()]    this_program recover_with(function(mixed, mixed ... : this_program) fun,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_success(p->success);    on_failure(apply_flat, p, fun, extra);    return p->future();    }       //! This specifies a callback that is only called on success, and    //! allows you to selectively alter the future into a failure.    //!    //! @param fun    //! Function to be called. The first argument will be the
pike.git/lib/modules/Concurrent.pmod:449:    //! as arguments two and onwards when the callback is called.    //!    //! @returns    //! The new @[Future].    //!    //! @seealso    //! @[transform()]    this_program filter(function(mixed, mixed ... : int(0..1)) fun,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_failure(p->failure);    on_success(apply_filter, p, fun, extra);    return p->future();    }       //! This specifies callbacks that allow you to alter the future.    //!    //! @param success    //! Function to be called. The first argument will be the    //! @b{success@} result of @b{this@} @[Future].
pike.git/lib/modules/Concurrent.pmod:487:    //! @note    //! This method is used if your callbacks return a regular value (i.e.    //! @b{not@} a @[Future]).    //!    //! @seealso    //! @[transform_with()], @[map()], @[recover()]    this_program transform(function(mixed, mixed ... : mixed) success,    function(mixed, mixed ... : mixed)|void failure,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_success(apply, p, success, extra);    on_failure(apply, p, failure || success, extra);    return p->future();    }       //! This specifies callbacks that allow you to alter the future.    //!    //! @param success    //! Function to be called. The first argument will be the    //! @b{success@} result of @b{this@} @[Future].
pike.git/lib/modules/Concurrent.pmod:526:    //!    //! @note    //! This method is used if your callbacks return a @[Future] again.    //!    //! @seealso    //! @[transform()], @[map_with()], @[recover_with]    this_program transform_with(function(mixed, mixed ... : this_program) success,    function(mixed, mixed ... : this_program)|void failure,    mixed ... extra)    { -  Promise p = Promise(); +  Promise p = promise_factory();    on_success(apply_flat, p, success, extra);    on_failure(apply_flat, p, failure || success, extra);    return p->future();    }       //! @param others    //! The other futures (results) you want to append.    //!    //! @returns    //! A new @[Future] that will be fulfilled with an
pike.git/lib/modules/Concurrent.pmod:584:    //! The new @[Future].    //!    //! @seealso    //! @[transform()], @[transform_with()], @[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,    void|function(mixed, mixed ... : mixed) onrejected,    mixed ... extra) { -  Promise p = Promise(); +  Promise p = promise_factory();    if (onfulfilled)    on_success(apply_smart, p, onfulfilled, extra);    else    on_success(p->success);    if (onrejected)    on_failure(apply_smart, p, onrejected, extra);    else    on_failure(p->failure);    return p->future();    }
pike.git/lib/modules/Concurrent.pmod:626:    //! @url{https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise@}    inline this_program thencatch(function(mixed, mixed ... : mixed) onrejected,    mixed ... extra) {    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(); +  Promise p = promise_factory();    on_failure(p->failure);    on_success(p->success);    if (timeout_call_out_handle) {    // Remove the previous timeout call_out.    (backend?backend->remove_call_out:remove_call_out)    (timeout_call_out_handle);    }    timeout_call_out_handle = (backend?backend->call_out:call_out)    (p->try_failure, seconds, ({ "Timeout.\n", backtrace() }));    return p->future();
pike.git/lib/modules/Concurrent.pmod:972:    _astate->results += futures;    }    return this_program::this;    }    inline variant this_program depend(Future ... futures)    {    return depend(futures);    }    variant this_program depend()    { -  Promise p = Promise(); +  Promise p = promise_factory();    depend(p->future());    return p;    }       //! @param initial    //! Initial value of the accumulator.    //!    //! @param fun    //! Function to apply. The first argument is the result of    //! one of the @[futures]. The second argument is the current value