Drain the pipe and fire callbacks. Since :attr:`_deferred` is
        synchronized, :meth:`defer` and :meth:`on_receive` can conspire to
        ensure only one byte needs to be pending regardless of queue length.
557387
def on_receive(self, broker):
        
        _vv and IOLOG.debug('%r.on_receive()', self)
        self._lock.acquire()
        try:
            self.receive_side.read(1)
            deferred = self._deferred
            self._deferred = []
        finally:
            self._lock.release()

        for func, args, kwargs in deferred:
            try:
                func(*args, **kwargs)
            except Exception:
                LOG.exception('defer() crashed: %r(*%r, **%r)',
                              func, args, kwargs)
                self._broker.shutdown()
173727
def +@
      response = Fiber.yield(Delayer::Deferred::Request::Await.new(self))
      if response.ok?
        response.value
      else
        Delayer::Deferred.fail(response.value)
      end
    end
450755
function(def, thisArg, func) {
            // The piped result will be available through a new Deferred.
            var d = new can.Deferred();
            def.then(function() {
                var args = can.makeArray(arguments),
                    success = true;

                try {
                    // Pipe the results through the function.
                    args[0] = func.apply(thisArg, args);
                } catch (e) {
                    success = false;
                    // The function threw an error, so reject the Deferred.
                    d.rejectWith(d, [e].concat(args));
                }
                if (success) {
                    // Resolve the new Deferred with the piped value.
                    d.resolveWith(d, args);
                }
            }, function() {
                // Pass on the rejection if the original Deferred never resolved.
                d.rejectWith(this, arguments);
            });

            // `can.ajax` returns a Deferred with an abort method to halt the AJAX call.
            if (typeof def.abort === 'function') {
                d.abort = function() {
                    return def.abort();
                };
            }

            // Return the new (piped) Deferred.
            return d;
        }
161716
function drainQueue(jobInfo) {
        function drainNext() {
            return drainQueue;
        }

        var queue = jobInfo.job._queue;

        if (queue.length === 0 && eventQueue.length > 0) {
            queue = jobInfo.job._queue = copyAndClearQueue();
        }

        jobInfo.setPromise(drainOneEvent(queue).then(drainNext, drainNext));
    }
636749
void deferBoundaryCallbacks(final boolean deferEmpty,
            final boolean deferBegin, final boolean deferEnd) {
        if (mBoundaryCallback == null) {
            throw new IllegalStateException("Can't defer BoundaryCallback, no instance");
        }

        /*
         * If lowest/highest haven't been initialized, set them to storage size,
         * since placeholders must already be computed by this point.
         *
         * This is just a minor optimization so that BoundaryCallback callbacks are sent immediately
         * if the initial load size is smaller than the prefetch window (see
         * TiledPagedListTest#boundaryCallback_immediate())
         */
        if (mLowestIndexAccessed == Integer.MAX_VALUE) {
            mLowestIndexAccessed = mStorage.size();
        }
        if (mHighestIndexAccessed == Integer.MIN_VALUE) {
            mHighestIndexAccessed = 0;
        }

        if (deferEmpty || deferBegin || deferEnd) {
            // Post to the main thread, since we may be on creation thread currently
            mMainThreadExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    // on is dispatched immediately, since items won't be accessed
                    //noinspection ConstantConditions
                    if (deferEmpty) {
                        mBoundaryCallback.onZeroItemsLoaded();
                    }

                    // for other callbacks, mark deferred, and only dispatch if loadAround
                    // has been called near to the position
                    if (deferBegin) {
                        mBoundaryCallbackBeginDeferred = true;
                    }
                    if (deferEnd) {
                        mBoundaryCallbackEndDeferred = true;
                    }
                    tryDispatchBoundaryCallbacks(false);
                }
            });
        }
    }
965782
def _connect_deferred(self, deferred):
        
        self._deferred = deferred

        # Because we use __del__, we need to make sure there are no cycles
        # involving this object, which is why we use a weakref:
        def put(result, eventual=weakref.ref(self)):
            eventual = eventual()
            if eventual:
                eventual._set_result(result)
            else:
                err(result, "Unhandled error in EventualResult")

        deferred.addBoth(put)
1310
def _process_callbacks(self):
        
        # Flush all the pipe content.
        os.read(self._schedule_pipe[0], 1024)

        # Process calls from executor.
        calls_from_executor, self._calls_from_executor = self._calls_from_executor, []
        for c in calls_from_executor:
            c()
709206
async def _drain_writer(self, timeout: NumType = None) -> None:
        
        if self._stream_writer is None:
            raise SMTPServerDisconnected("Client not connected")

        # Wrapping drain in a task makes mypy happy
        drain_task = asyncio.Task(self._stream_writer.drain(), loop=self._loop)
        try:
            await asyncio.wait_for(drain_task, timeout, loop=self._loop)
        except ConnectionError as exc:
            raise SMTPServerDisconnected(str(exc))
        except asyncio.TimeoutError as exc:
            raise SMTPTimeoutError(str(exc))
975009
def pipe_data_received(self, fd, data):
        """"""
        if fd == 2:  # stderr fd number
            self._on_stderr(data)
        elif self._on_data:
            self._on_data(data)
        else:
            self._queued_data.append(data)
766454
function() {
      var resultDeferred = $.Deferred();
      if (this.isDisposed()) {
        var rejectArguments = Array.prototype.slice.call(arguments);
        rejectArguments.push('Data Behavior disposed, aborting.');
        resultDeferred.reject.apply(resultDeferred, rejectArguments);
      } else {
        resultDeferred.resolve.apply(resultDeferred, arguments);
      }
      return resultDeferred.promise();
    }
1265088
function Deferred() {
    var self = this;
    self.promise = new Promise(function (resolve, reject) {
        self.resolve = resolve;
        self.reject = reject;
    });
}
1176406
def waitForDeferred(d, result=None):
    """"""
    from twisted.internet import reactor
    assert reactor.greenlet != getcurrent(), "can't invoke this in the reactor greenlet"
    if result is None:
        result = AsyncResult()

    def cb(res):
        if isinstance(res, defer.Deferred):
            waitForDeferred(res, result)
        else:
            result.set(res)

    def eb(res):
        result.set_exception(res)

    d.addCallbacks(cb, eb)
    try:
        return result.get()
    except failure.Failure, ex:
        ex.raiseException()
957938
def defer(callable):
    '''
    '''
    t = threading.Thread(target=callable)
    t.start()
    return t.join
563467
function defer() {
  const def = promiseDefer();

  def.apply = function (err, result) {
    if (err) {
      def.reject(err);
    } else {
      def.resolve(result);
    }
  };

  return def;
}
535928
def drain(self, tab_key):
		'''
		
		'''
		self.log.debug("Draining transport")
		ret = []
		while len(self.messages[tab_key]):
			ret.append(self.messages[tab_key].pop(0))

		self.log.debug("Polling socket")

		tmp = self.___recv(tab_key)
		while tmp is not None:
			ret.append(tmp)
			tmp = self.___recv(tab_key)

		self.log.debug("Drained %s messages", len(ret))
		return ret
166486
def block(self, *args, **kwargs):
        
        LOG.debug(
            '%s on %s (awaitable %s async %s provider %s)',
            'blocking',
            self._func,
            self._is_awaitable,
            self._is_asyncio_provider,
            self._concurrency_provider
        )

        if self._deferable:
            raise RuntimeError('Already activated this call by deferring it')
        with self._lock:
            if not hasattr(self, '_result'):
                try:
                    self._result = (
                        self._concurrency_provider.run_until_complete(self.defer(*args, **kwargs))
                        if self._is_asyncio_provider else self._func(*args, **kwargs)
                    )
                except queue.Empty:
                    raise CloudTimeoutError("No data received after %.1f seconds." % kwargs.get("timeout", 0))
            self._blocked = True
        return self._result
53400
def drain(self, p):
        ''''''

        self.logging.info('Started.')
        fd = os.open(p, os.O_RDWR | os.O_NONBLOCK)
        gevent_os.make_nonblocking(fd)

        while self.loop():
            try:
                lines = gevent_os.nb_read(fd, 4096).splitlines()
                if len(lines) == 0:
                    sleep(0.5)
                else:
                    self.consume(lines)
            except OSError:
                pass