Q defer resolving when all processes are closed
184189
function () {
    if (processes && processes.length > 0) {
        for (var i = processes.length - 1; i >= 0; i--) {
            processes[i].kill();
        }
    }
}
348218
public void defer(ICommandData[] commands) {
        deferredCommands.addAll(Arrays.asList(commands));
        for (ICommandData command : commands) {
            deferInternal(command);
        }
    }
48635
function handleTernCompletions(response) {

        var file = response.file,
            offset = response.offset,
            completions = response.completions,
            properties = response.properties,
            fnType  = response.fnType,
            type = response.type,
            error = response.error,
            $deferredHints = getPendingRequest(file, offset, type);

        if ($deferredHints) {
            if (error) {
                $deferredHints.reject();
            } else if (completions) {
                $deferredHints.resolveWith(null, [{completions: completions}]);
            } else if (properties) {
                $deferredHints.resolveWith(null, [{properties: properties}]);
            } else if (fnType) {
                $deferredHints.resolveWith(null, [fnType]);
            }
        }
    }
1333407
async def delayNdefProps(self):
        '''
        
        '''
        async with self.getTempSlab() as slab:

            seqn = s_slabseqn.SlabSeqn(slab, 'ndef')

            self.ndefdelay = seqn

            yield

            self.ndefdelay = None

            logger.info(f'Processing {seqn.index()} delayed values.')

            # process them all now...
            for i, (oldv, newv) in seqn.iter(0):
                await self.editNdefProps(oldv, newv)

                if i and i % _progress == 0:
                    logger.info(f'Processed {i} delayed values.')
728894
def delayed_close(self):
        """"""
        self.state = CLOSING
        self.server.io_loop.add_callback(self.close)
962159
function freezeAllProcessDir(dir, basePath, result) {
    fs.readdirSync(dir).forEach(function(file) {
        file = PATH.resolve(dir, file);
        var stat = fs.statSync(file);
        if (stat.isFile()) {
            freezeAllProcessFile(file, basePath, result);

        } else if (stat.isDirectory()) {
            freezeAllProcessDir(file, basePath, result);
        }
    });
}
1170880
def deferred_cleanup(fn):
    """"""
    @functools.wraps(fn)
    def ret(*args, **kwargs):
        defers = []
        try:
            ret = fn(lambda *args: defers.extend(args), *args, **kwargs)
        finally:
            for defer in reversed(defers):
                defer()
        return ret
    return ret
787158
def _wait_for_process(self, pid, name):
        
        try:
            logging.debug("Waiting for process %s with pid %s", name, pid)
            unused_pid, exitcode, ru_child = os.wait4(pid, 0)
            return exitcode, ru_child
        except OSError as e:
            if self.PROCESS_KILLED and e.errno == errno.EINTR:
                # Interrupted system call seems always to happen
                # if we killed the process ourselves after Ctrl+C was pressed
                # We can try again to get exitcode and resource usage.
                logging.debug("OSError %s while waiting for termination of %s (%s): %s.",
                              e.errno, name, pid, e.strerror)
                try:
                    unused_pid, exitcode, ru_child = os.wait4(pid, 0)
                    return exitcode, ru_child
                except OSError:
                    pass # original error will be handled and this ignored

            logging.critical("OSError %s while waiting for termination of %s (%s): %s.",
                             e.errno, name, pid, e.strerror)
            return (0, None)
244642
def managed_process(process):
    """"""
    try:
        yield process
    finally:
        for stream in [process.stdout, process.stdin, process.stderr]:
            if stream:
                stream.close()
        process.wait()
1312677
def processEnded(self, reason):
        
        log_debug("{name} process exited", name=self.name)
        if self.deferred:
            if reason.type == ProcessDone:
                self.deferred.callback(reason.value.exitCode)
            elif reason.type == ProcessTerminated:
                self.deferred.errback(reason)
        return self.deferred
846175
def _on_closed(self):
        """"""
        LOGGER.error('Redis connection closed')
        self.connected = False
        self._on_close()
        self._stream = None
930329
function(name, brk, debugChildren) {
		var deferred = Q.defer();
		var args = process.argv;
		
		grunt.task.clearQueue();
		
		var tasks = args.slice(args.indexOf(name) + 1);
		
		if (debugChildren) {
			tasks.unshift('debug:hook' + (brk ? '-break' : ''));
		}
		
		var child = child_process.fork(
			args[1],
			tasks,
			{
				execArgv: [
					brk
						? '--debug-brk'
						: '--debug'
				]
			}
		);
		
		child.on('exit', function(code) {
			if (code == 0) {
				deferred.resolve();
			}
			else {
				deferred.reject(code);
			}
		});
		
		return deferred.promise;
	}
314457
function restartProcessing (q) {
  logger('restartProcessing')
  setTimeout(function randomRestart () {
    queueProcess.restart(q)
  }, Math.floor(Math.random() * 1000))
}
901065
private CompletableFuture<Void> flush(Void ignored) {
        checkRunning();
        long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "flush");

        // Flush everything we can flush.
        val flushFutures = this.processors.values().stream()
                                          .filter(ProcessorCollection::mustFlush)
                                          .map(a -> a.flush(this.config.getFlushTimeout()))
                                          .collect(Collectors.toList());

        return Futures
                .allOfWithResults(flushFutures)
                .thenAcceptAsync(flushResults -> {
                    FlushStageResult result = new FlushStageResult();
                    flushResults.forEach(result::withFlushResult);
                    if (result.getFlushedBytes() + result.getMergedBytes() + result.count > 0) {
                        logStageEvent("Flush", result);
                    }

                    LoggerHelpers.traceLeave(log, this.traceObjectId, "flush", traceId);
                }, this.executor);
    }
290316
function(err, res) {
    if (_.isFunction(callback)) {
      try {
        res = callback(err, res);
        err = null;
      } catch(e) {
        err = e;
      }
    }
    if (err) {
      deferred.reject(err);
    } else {
      deferred.resolve(res);
    }
  }
1266242
def wait(self):
        
        ret = os.read(self.event_fd, 64 / 8)
        return struct.unpack('Q', ret)
338990
@Override
    public void resolve(final Response<T> response) {
        if (!isPending()) {
            throw new IllegalStateException("Deferred object already finished, cannot resolve again");
        }

        state = State.RESOLVED;
        resolveResult = response.getPayload();

        try {
            triggerDone(response);
        } finally {
            triggerAlways(resolveResult, null);
        }
    }