pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:152:    //! @seealso    //! @[set_backend()], @[use_backend()]    protected void call_callback(function cb, mixed ... args)    {    (backend ? backend->call_out : callout)(cb, 0, @args);    }       //! Wait for fulfillment.    //!    //! @seealso -  //! @[get()] +  //! @[get()], @[try_get()]    this_program wait()    {    if (state <= STATE_PENDING) {    Thread.MutexKey key = mux->lock();    while (state <= STATE_PENDING) {    cond->wait(key);    }    }       return this;    }       //! Wait for fulfillment and return the value.    //!    //! @throws    //! Throws on rejection.    //!    //! @seealso -  //! @[wait()] +  //! @[wait()], @[try_get()]    mixed get()    {    wait();       if (state >= STATE_REJECTED) {    throw(result);    }    return result;    }    -  +  //! Return the value if available. +  //! +  //! @returns +  //! Returns @[UNDEFINED] if the @[Future] is not yet fulfilled. +  //! +  //! @throws +  //! Throws on rejection. +  //! +  //! @seealso +  //! @[wait()] +  mixed try_get() +  { +  switch(state) { +  case ..STATE_PENDING: +  return UNDEFINED; +  case STATE_REJECTED..: +  throw(result); +  default: +  return result; +  } +  } +     //! Register a callback that is to be called on fulfillment.    //!    //! @param cb    //! Function to be called. The first argument will be the    //! result of the @[Future].    //!    //! @param extra    //! Any extra context needed for @[cb]. They will be provided    //! as arguments two and onwards when @[cb] is called.    //!