Branch: Tag:

2019-02-15

2019-02-15 14:07:14 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Concurrent.Future: Added internal function call_callback().

This makes it possible to adjust the way that callbacks are
called via overloading. The typical use case is for wanting
callbacks to be called by some other thread than the backend.

80:    protected array(array(function(mixed, mixed ...: void)|mixed))    failure_cbs = ({});    +  //! Call a callback function. +  //! +  //! @param cb +  //! Callback function to call. +  //! +  //! @param args +  //! Arguments to call @[cb] with. +  protected void call_callback(function cb, mixed ... args) +  { +  callout(cb, 0, @args); +  } +     //! Wait for fulfillment and return the value.    //!    //! @throws
123:    {    switch (state) {    case STATE_FULFILLED: -  callout(cb, 0, result, @extra); +  call_callback(cb, result, @extra);    break;    case STATE_PENDING:    // Rely on interpreter lock to add to success_cbs before state changes
152:    {    switch (state) {    case STATE_REJECTED: -  callout(cb, 0, result, @extra); +  call_callback(cb, result, @extra);    break;    case STATE_PENDING:    // Rely on interpreter lock to add to failure_cbs before state changes
770:    {    foreach(cbs; ; array cb)    if (cb) -  callout(cb[0], 0, value, @cb[1..]); +  call_callback(cb[0], value, @cb[1..]);    }    else if (globalfailure) -  callout(globalfailure, 0, value); +  call_callback(globalfailure, value);    failure_cbs = success_cbs = 0; // Free memory and references    }    else