pike.git / lib / modules / Concurrent.pmod

version» Context lines:

pike.git/lib/modules/Concurrent.pmod:16:      //! Global failure callback, called when a promise without failure   //! callback fails. This is useful to log exceptions, so they are not   //! just silently caught and ignored.   void on_failure(function(mixed : void) f)   {    global_on_failure = f;   }   protected function(mixed : void) global_on_failure;    + //! @param enable + //! Setting this to @expr{false@} causes all @[Concurrent] callbacks + //! to be called directly, without using a backend (except for timeouts). + final void use_backend(int enable) + { +  callout = enable ? call_out : callnow; + } +  + private mixed +  callnow(function(mixed ...:void) f, int|float delay, mixed ... args) + { +  f(@args); +  return 0; + } +  + 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;    State state;   
pike.git/lib/modules/Concurrent.pmod:77:    //! @[cb] will always be called from the main backend.    //!    //! @seealso    //! @[on_failure()]    this_program on_success(function(mixed, mixed ... : void) cb, mixed ... extra)    {    Thread.MutexKey key = mux->lock();       if (state == STATE_FULFILLED) {    key = 0; -  call_out(cb, 0, result, @extra); +  callout(cb, 0, result, @extra);    } else {    success_cbs += ({ ({ cb, @extra }) });    key = 0;    }       return this_program::this;    }       //! Register a callback that is to be called on failure.    //!
pike.git/lib/modules/Concurrent.pmod:107:    //! @[cb] will always be called from the main backend.    //!    //! @seealso    //! @[on_success()]    this_program on_failure(function(mixed, mixed ... : void) cb, mixed ... extra)    {    Thread.MutexKey key = mux->lock();       if (state == STATE_REJECTED) {    key = 0; -  call_out(cb, 0, result, @extra); +  callout(cb, 0, result, @extra);    } else {    failure_cbs += ({ ({ cb, @extra }) });    key = 0;    }       return this_program::this;    }       //! Apply @[fun] with @[val] followed by the contents of @[ctx],    //! and update @[p] with the result.
pike.git/lib/modules/Concurrent.pmod:634:    if (!state)    {    state = newstate;    result = value;    key = 0;    cond->broadcast();    if (sizeof(cbs))    {    foreach(cbs; ; array cb)    if (cb) -  call_out(cb[0], 0, value, @cb[1..]); +  callout(cb[0], 0, value, @cb[1..]);    }    else if (globalfailure) -  call_out(globalfailure, 0, value); +  callout(globalfailure, 0, value);    }    else    {    key = 0;    if (!try)    error("Promise has already been finalised.\n");    }    return this_program::this;    }