pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:48:   protected function(function(mixed ...:void), int|float, mixed ...:mixed)    callout = call_out;      //! Value that will be provided asynchronously   //! sometime in the future.   //!   //! @seealso   //! @[Promise]   class Future   { -  mixed result = UNDEFINED; +  mixed result;    State state;       protected array(array(function(mixed, mixed ...: void)|mixed))    success_cbs = ({});    protected array(array(function(mixed, mixed ...: void)|mixed))    failure_cbs = ({});       //! Wait for fulfillment and return the value.    //!    //! @throws
pike.git/lib/modules/Concurrent.pmod:144:    }    return this_program::this;    }       //! Apply @[fun] with @[val] followed by the contents of @[ctx],    //! and update @[p] with the result.    protected void apply(mixed val, Promise p,    function(mixed, mixed ... : mixed) fun,    array(mixed) ctx)    { -  mixed err = catch { -  p->success(fun(val, @ctx)); -  return; -  }; +  mixed f; +  if (mixed err = catch (f = fun(val, @ctx)))    p->failure(err); -  +  else +  p->success(f);    }       //! Apply @[fun] with @[val] followed by the contents of @[ctx],    //! and update @[p] with the eventual result.    protected void apply_flat(mixed val, Promise p,    function(mixed, mixed ... : Future) fun,    array(mixed) ctx)    { -  mixed err = catch { -  Future f = fun(val, @ctx); -  if (!objectp(f) || !f->on_failure || !f->on_success) { -  error("Expected %O to return a Future. Got: %O.\n", -  fun, f); +  Future f; +  { +  if (mixed err = catch (f = fun(val, @ctx))) { +  p->failure(err); +  return;    } -  +  } +  if (!objectp(f) || !f->on_failure || !f->on_success) +  error("Expected %O to return a Future. Got: %O.\n", fun, f);    f->on_failure(p->failure)->on_success(p->success); -  return; -  }; -  p->failure(err); +     }       //! Apply @[fun] with @[val] followed by the contents of @[ctx],    //! and update @[p] with the eventual result.    protected void apply_smart(mixed val, Promise p,    function(mixed, mixed ... : mixed|Future) fun,    array(mixed) ctx)    { -  mixed err = catch { -  mixed|Future f = fun(val, @ctx); -  if (!objectp(f) -  || !functionp(f->on_failure) || !functionp(f->on_success)) { -  p->success(f); +  mixed|Future f; +  { +  if (mixed err = catch (f = fun(val, @ctx))) { +  p->failure(err);    return;    } -  +  } +  if (!objectp(f) +  || !functionp(f->on_failure) || !functionp(f->on_success)) +  p->success(f); +  else    f->on_failure(p->failure)->on_success(p->success); -  return; -  }; -  p->failure(err); +     }       //! Apply @[fun] with @[val] followed by the contents of @[ctx],    //! and update @[p] with @[val] if @[fun] didn't return false. -  //! If @[fun] returned false fail @[p] with @[UNDEFINED]. +  //! If @[fun] returned false, fail @[p] with @expr{0@} as result.    protected void apply_filter(mixed val, Promise p,    function(mixed, mixed ... : int(0..1)) fun,    array(mixed) ctx)    { -  mixed err = catch { -  if (fun(val, @ctx)) { +  int bool; +  mixed err; +  if (!(err = catch (bool = fun(val, @ctx))) && bool)    p->success(val); -  } else { -  p->failure(UNDEFINED); -  } -  return; -  }; +  else    p->failure(err);    }       //! 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    //! @b{success@} result of @b{this@} @[Future].    //! The return value will be the success result of the new @[Future].