see IPromise (inheriting Callback) interface
776184
@Override
    public IPromise then(Callback resultCB) {
        // FIXME: this can be implemented more efficient
        while( !lock.compareAndSet(false,true) ) {}
        try {
            if (resultReceiver != null)
                throw new RuntimeException("Double register of promise listener");
            resultReceiver = resultCB;
            if (hadResult) {
                hasFired = true;
                if (nextFuture == null) {
                    nextFuture = new Promise(result, error);
                    lock.set(false);
                    resultCB.complete(result, error);
                } else {
                    lock.set(false);
                    resultCB.complete(result, error);
                    nextFuture.complete(result, error);
                    return nextFuture;
                }
            }
            if (resultCB instanceof IPromise) {
                return (IPromise) resultCB;
            }
            lock.set(false);
            while( !lock.compareAndSet(false,true) ) {}
            if (nextFuture == null) {
                return nextFuture = new Promise();
            } else {
                return nextFuture;
            }
        } finally {
            lock.set(false);
        }
    }
638310
function init() {
			if (!oInitPromise) {
				oInitPromise = new Promise(function(resolve, reject) {

					oWorker = new window.Worker(WORKER.URL);

					// listen for confirmation from worker
					oWorker.addEventListener('message', function(oEvent) {
						var oData = oEvent.data;
						resolve(oData && oData[WORKER.RESPONSE_FIELDS.DONE] === true);
					}, false);

					// instruct the worker to fetch the index data
					oWorker.postMessage({
						"cmd": WORKER.COMMANDS.INIT,
						"bIsMsieBrowser": !!Device.browser.msie
					});
				});
			}

			return oInitPromise;
		}
454254
function callProcessor(eventType, data, callback) {
    var p = processors[eventType];
    // no processors
    if (p===undefined || p.length==0) {
      if (callback!==undefined) callback(data);
      return;
    }
    // now go through all processors
    var n = 0;
    var cbCalled = false;
    var cb = function(inData) {
      if (cbCalled) throw new Error("Internal error in "+eventType+" processor. Callback is called TWICE.");
      cbCalled = true;
      if (n < p.length) {
        cbCalled = false;
        p[n++](inData, cb);
      } else {
        if (callback!==undefined) callback(inData);
      }
    };
    cb(data);
  }
317233
public void readLed(Callback<LedColor> callback) {
        addCallback(BeanMessageID.CC_LED_READ_ALL, callback);
        sendMessageWithoutPayload(BeanMessageID.CC_LED_READ_ALL);
    }
426333
function(callback) {
		
		if(!this.ifLoad) {
			this.stack(this.pngToData, callback);
			return;
		}
		
		this.history.push('png decode');
		
		var that = this;
		
		var png = new this.png_node(this.data);
		png.decode(function (pixels) {
			
			that.width = png.width;
			that.height = png.height;
			that.data = pixels;
			that.bpp = 4;
			callback.call(that);
		});
		
		return;		
	}
438903
def interface(self, context):
        """"""
        self.context = context
        self.callback = self.context.get("callback")
446814
def inherit_docstrings(cls):
    
    @functools.wraps(cls)
    def _inherit_docstrings(cls):
        if not isinstance(cls, (type, colorise.compat.ClassType)):
            raise RuntimeError("Type is not a class")

        for name, value in colorise.compat.iteritems(vars(cls)):
            if isinstance(getattr(cls, name), types.MethodType):
                if not getattr(value, '__doc__', None):
                    for base in cls.__bases__:
                        basemethod = getattr(base, name, None)

                        if basemethod and getattr(base, '__doc__', None):
                            value.__doc__ = basemethod.__doc__

        return cls

    return _inherit_docstrings(cls)
1240363
function watchColorPaletteFile(filePath, callback) {
  chokidar
    .watch(filePath, {
      ignoreInitial: true,
    })
    .on('all', function(event, path, stats) {
      if (event === 'add' || event === 'change') {
        getFileHash(filePath, function(hash) {
          if (hash !== colorPaletteHash) {
            colorPaletteHash = hash;
            console.log('Color palette changed! Invalidating cache...');
            callback();
          }
        });
      }
    });
}
1175608
def chain_callback(self, iocb):
        """"""
        if _debug: IOChainMixIn._debug("chain_callback %r", iocb)

        # if we're not chained, there's no notification to do
        if not self.ioChain:
            return

        # refer to the chained iocb
        iocb = self.ioChain

        try:
            if _debug: IOChainMixIn._debug("    - decoding")

            # let the derived class transform the data
            self.decode()

            if _debug: IOChainMixIn._debug("    - decode complete")
        except:
            # extract the error and abort
            err = sys.exc_info()[1]
            if _debug: IOChainMixIn._exception("    - decoding exception: %r", err)

            iocb.ioState = ABORTED
            iocb.ioError = err

        # break the references
        self.ioChain = None
        iocb.ioController = None

        # notify the client
        iocb.trigger()
1296461
function showInterfaceIdlMethod(method, html) {
    var line = "\n   "

    var allParameters = method.parameters.concat(method.callbackParameters)

    line += getIdlType(method.returns)
    line += " <span class='methodName'>" + method.name + "</span> (" + getIdlParameterList(allParameters) + ");"
    html.push(line)
}
99870
function (thisProperty, callbackArgs) {
                return function (callback) {

                    function notifyListener() {
                        if (Model.asyncEvents) {
                            setTimeout(function () {
                                callback.apply(thisProperty, callbackArgs);
                            }, 0);
                        } else {
                            callback.apply(thisProperty, callbackArgs);
                        }
                    }

                    if (Model.TRANSACTION_OPTIONS.flattenCallbacks || Model.TRANSACTION_OPTIONS.flattenCallbacksByHash) {
                        var callbackExecuted = false;
                        if (Model.TRANSACTION_OPTIONS.flattenCallbacks) {
                            if (executedCallbacks.indexOf(callback) === -1) { // Only call callback once
                                executedCallbacks.push(callback);
                                notifyListener();
                                callbackExecuted = true;
                            }
                        }
                        if (Model.TRANSACTION_OPTIONS.flattenCallbacksByHash) {
                            if (!callback.hash || callbackHashs.indexOf(callback.hash) === -1) { // Only call hash identified callback once
                                if (callback.hash) {
                                    callbackHashs.push(callback.hash);
                                }
                                if (!callbackExecuted) {
                                    notifyListener();
                                    callbackExecuted = true;
                                }
                            }
                        }
                    } else {
                        notifyListener();
                    }
                };
            }
1199228
def green_callback(fn, obj=None, green_mode=None):
    """"""
    executor = get_object_executor(obj, green_mode)

    @wraps(fn)
    def greener(*args, **kwargs):
        return executor.submit(fn, *args, **kwargs)

    return greener
818508
function (object, callbacks) {
    callbacks = callbacks || { };

    var empty = function() { },
        onComplete = callbacks.onComplete || empty,
        onChange = callbacks.onChange || empty,
        _this = this;

    fabric.util.animate({
      startValue: object.get('opacity'),
      endValue: 0,
      duration: this.FX_DURATION,
      onStart: function() {
        object.setActive(false);
      },
      onChange: function(value) {
        object.set('opacity', value);
        _this.renderAll();
        onChange();
      },
      onComplete: function () {
        _this.remove(object);
        onComplete();
      }
    });

    return this;
  }
1291827
def callbacks(cls, eventType=None):
        
        key = '_{0}__callbacks'.format(cls.__name__)
        try:
            callbacks = getattr(cls, key)
        except AttributeError:
            callbacks = {}
            setattr(cls, key, callbacks)

        return callbacks.get(eventType, []) if eventType is not None else callbacks
61307
def group_callback(self, iocb):
        """"""
        if _debug: IOGroup._debug("group_callback %r", iocb)

        # check all the members
        for iocb in self.ioMembers:
            if not iocb.ioComplete.isSet():
                if _debug: IOGroup._debug("    - waiting for child: %r", iocb)
                break
        else:
            if _debug: IOGroup._debug("    - all children complete")
            # everything complete
            self.ioState = COMPLETED
            self.trigger()
129151
@Override
    public IPromise<T> thenAnd(Supplier<IPromise<T>> callable) {
        Promise res = new Promise<>();
        then( new Callback<T>() {
            @Override
            public void complete(T result, Object error) {
                if ( Actor.isError(error) ) {
                    res.complete(null, error);
                } else {
                    IPromise<T> call = null;
                    call = callable.get().then(res);
                }
            }
        });
        return res;
    }
1243283
function eventToPromise (emitter, event, opts) {
  var cancel
  var promise = new Promise(function (resolve, reject) {
    var addEvent = makeEventAdder(emitter, opts && opts.array)
    cancel = function () {
      cancel = noop
      addEvent.cleanUp()
    }

    addEvent(event, resolve)

    if (!opts || !opts.ignoreErrors) {
      addEvent((opts && opts.error) || 'error', reject)
    }
  })
  promise.cancel = function () { return cancel() }

  return promise
}