pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:40:       //! Wait for fulfillment and return the value.    //!    //! @throws    //! Throws on rejection.    mixed get()    {    State s = state;    mixed res = result;    if (!s) { -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    while (!state) {    cond->wait(key);    }       s = state;    res = result;    key = 0;    }       if (s == STATE_REJECTED) {
pike.git/lib/modules/Concurrent.pmod:73:    //! Any extra context needed for @[cb]. They will be provided    //! as arguments two and onwards when @[cb] is called.    //!    //! @note    //! @[cb] will always be called from the main backend.    //!    //! @seealso    //! @[on_failure()]    this_program on_success(function(mixed, mixed ... : void) cb, mixed ... extra)    { -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();       if (state == STATE_FULFILLED) {    call_out(cb, 0, result, @extra);    key = 0;    return this_program::this;    }       success_cbs += ({ ({ cb, extra }) });    key = 0;   
pike.git/lib/modules/Concurrent.pmod:104:    //! Any extra context needed for @[cb]. They will be provided    //! as arguments two and onwards when @[cb] is called.    //!    //! @note    //! @[cb] will always be called from the main backend.    //!    //! @seealso    //! @[on_success()]    this_program on_failure(function(mixed, mixed ... : void) cb, mixed ... extra)    { -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();       if (state == STATE_REJECTED) {    call_out(cb, 0, result, @extra);    key = 0;    return this_program::this;    }       failure_cbs += ({ ({ cb, extra }) });    key = 0;   
pike.git/lib/modules/Concurrent.pmod:340:       //! @returns    //! A @[Future] that will be fulfilled with an    //! array of the fulfilled result of this object followed    //! 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); +  return sizeof(others) +  ? results(({ this_program::this }) + others) +  : this_program::this;    }       //! JavaScript Promise API close but not identical equivalent    //! of a combined @[transform()] and @[transform_with()].    //!    //! @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].    //! If the return value already is a @[Future], pass it as-is.
pike.git/lib/modules/Concurrent.pmod:486:    }       private void fold(function(mixed:void) failsucc) {    failsucc(fold_fun ? accumulator : results);    results = 0; // Free memory    }       private void cb_failure(mixed value, int idx) {    Promise p; // Cache it, to cover a failure race    if (p = promise) { -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    do {    if (!p->state) {    ++failed;    if (max_failures < failed && max_failures >= 0) {    key = 0;    p->try_failure(value);    break;    }    int success = succeeded + failed == promises;    key = 0;
pike.git/lib/modules/Concurrent.pmod:516:    key = 0;    return;    } while (0);    promise = 0; // Free backreference    }    }       private void cb_success(mixed value, int idx) {    Promise p; // Cache it, to cover a failure race    if (p = promise) { -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    do {    if (!p->state) {    ++succeeded;    if (promises - min_failures < succeeded) {    key = 0;    p->try_failure(value);    break;    }    int success = succeeded + failed == promises;    key = 0;
pike.git/lib/modules/Concurrent.pmod:626:    //! or failed.    //!    //! Mark the @[Future] as fulfilled, and schedule the @[on_success()]    //! callbacks to be called as soon as possible.    //!    //! @seealso    //! @[try_success()], @[try_failure()], @[failure()], @[on_success()]    void success(mixed value)    {    if (state) error("Promise has already been finalised.\n"); -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    if (state) error("Promise has already been finalised.\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(); +  Thread.MutexKey key = mux->lock();    if (state) return;    unlocked_success(value);    key = 0;    }       protected void unlocked_failure(mixed value)    {    state = STATE_REJECTED;    result = value;    cond->broadcast();
pike.git/lib/modules/Concurrent.pmod:685:    //! or failed.    //!    //! Mark the @[Future] as failed, and schedule the @[on_failure()]    //! callbacks to be called as soon as possible.    //!    //! @seealso    //! @[try_failure()], @[success()], @[on_failure()]    void failure(mixed value)    {    if (state) error("Promise has already been finalised.\n"); -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    if (state) error("Promise has already been finalised.\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 in that case schedule the @[on_failure()] callbacks to be    //! called as soon as possible.    //!    //! @seealso    //! @[failure()], @[success()], @[on_failure()]    void try_failure(mixed value)    {    if (state) return; -  object key = mux->lock(); +  Thread.MutexKey key = mux->lock();    if (state) return;    unlocked_failure(value);    }       inline private void fill_astate() {    if (!_astate)    _astate = aggregate_state(this);    }       //! Add futures to the list of futures which the current object depends upon.    //!    //! If called without arguments it will produce a new @[Future]    //! from a new @[Promise] which is implictly added to the dependency list.    //!    //! @param futures -  //! The list of @expr{futures@} we want to add to the list we depend on. +  //! The list of @expr{futures@} we want to add to the list we depend upon.    //!    //! @returns    //! The new @[Promise].    //!    //! @note    //! Can be called multiple times to add more.    //!    //! @note    //! Once the promise has been materialised (when either @[on_success()],    //! @[on_failure()] or @[get()] has been called on this object), it is
pike.git/lib/modules/Concurrent.pmod:907:    return first_completed(futures);   }      //! @returns   //! A @[Future] that represents the array of all the completed @expr{futures@}.   //!   //! @seealso   //! @[all()], @[Promise.depend()]   variant Future results(array(Future) futures)   { -  Promise p = Promise(); -  p->depend(futures); -  return p->future(); +  return Promise()->depend(futures)->future();   }   inline variant Future results(Future ... futures)   {    return results(futures);   }      //! JavaScript Promise API equivalent of @[results()].   //!   //! @seealso   //! @[results()], @[Promise.depend()]
pike.git/lib/modules/Concurrent.pmod:938:   }      //! @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->future(); +  return Promise()->failure(reason)->future();   }      //! @returns   //! A new @[Future] that has already been fulfilled with @expr{value@}   //! as result. If @expr{value@} is an object which already   //! 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) && value->on_failure && value->on_success) -  return value; -  object p = Promise(); -  p->success(value); -  return p->future(); +  return objectp(value) && value->on_failure && value->on_success +  ? value +  : Promise()->success(value)->future();   }      //! 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,    mixed ... extra)   {    return results(futures->map(fun, @extra));   }
pike.git/lib/modules/Concurrent.pmod:996:   //! @note   //! @[fun] may be called in any order, and will be called   //! once for every @[Future] in @[futures], unless one of   //! calls fails in which case no further calls will be   //! performed.   Future fold(array(Future) futures,    mixed initial,    function(mixed, mixed, mixed ... : mixed) fun,    mixed ... extra)   { -  Promise p = Promise(); -  p->depend(futures); -  p->fold(initial, fun, extra); -  return p->future(); +  return Promise()->depend(futures)->fold(initial, fun, extra)->future();   }