pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:470:    futures->on_failure(failure);       foreach(futures; int i; Future f) {    f->on_success(got_success, i, results, states);    }    }       protected void got_success(mixed value, int i,    array(mixed) results, array(State) states)    { -  if (state == STATE_REJECTED) return; +  if (state || states[i]) return; +  object key = mux->lock(); +  if (state || states[i]) return;    results[i] = value;    states[i] = STATE_FULFILLED; -  if (!state) { +     if (has_value(states, STATE_PENDING)) {    return;    } -  } +  key = 0;    success(results);    }   }      //! Return a @[Future] that represents the array of all   //! the completed @[futures].   Future results(array(Future) futures)   {    Promise p = Results(futures);    return p->future();
pike.git/lib/modules/Concurrent.pmod:528:    allocate(sizeof(futures), STATE_PENDING));    }    }       protected void got_success(mixed val, int i,    function(mixed, mixed, mixed ... : mixed) fun,    array(mixed) ctx,    array(State) states)    {    if (state || states[i]) return; +  object key = mux->lock(); +  if (state || states[i]) return;    states[i] = STATE_FULFILLED;    mixed err = catch {    // FIXME: What if fun triggers a recursive call?    accumulated = fun(val, accumulated, @ctx); -  if (!state) { +     if (has_value(states, STATE_PENDING)) return; -  } +     success(accumulated);    return;    };    failure(err);    }   }      //! Return a @[Future] that represents the accumulated results of   //! applying @[fun] to the results of the @[futures] in turn.   //!   //! @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 the current accumulated   //! value, and any further from @[extra].   //!   //! @note - //! @[fun] may be called in any order, and will only be called - //! once for every @[Future] in @[futures]. + //! If @[fun] throws an error it will fail the @[Future]. + //! + //! @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 = Fold(futures, initial, fun, extra);    return p->future();   }