Wait for the client to close, then emit a cancelled event if the client
cancelled.
@private
504939
function waitForCancel() {
  /* jshint validthis: true */
  var self = this;
  var cancel_batch = {};
  cancel_batch[grpc.opType.RECV_CLOSE_ON_SERVER] = true;
  self.call.startBatch(cancel_batch, function(err, result) {
    if (err) {
      self.emit('error', err);
    }
    if (result.cancelled) {
      self.cancelled = true;
      self.emit('cancelled');
    }
  });
}
874153
function () {
    clearTimeout(timeoutId);
    var args = [];
    for (var index = 0, length = arguments.length; index < length; index++) {
      args.push(arguments[index]);
    }
    self.socketEvent = {
      namespace: action.namespace,
      eventType: action.eventType,
      args: args
    };
    callback(null, self.socketEvent);
  }
728894
def delayed_close(self):
        """"""
        self.state = CLOSING
        self.server.io_loop.add_callback(self.close)
814918
function onTimeout() {
    const listenerCount = socket.listeners('timeout').length;
    debug('%s(requests: %s, finished: %s) timeout after %sms, listeners %s',
      socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
      getSocketTimeout(socket), listenerCount);
    agent.timeoutSocketCount++;
    const name = agent.getName(options);
    if (agent.freeSockets[name] && agent.freeSockets[name].indexOf(socket) !== -1) {
      // free socket timeout, destroy quietly
      socket.destroy();
      // Remove it from freeSockets list immediately to prevent new requests
      // from being sent through this socket.
      agent.removeSocket(socket, options);
      debug('%s is free, destroy quietly', socket[SOCKET_NAME]);
    } else {
      // if there is no any request socket timeout handler,
      // agent need to handle socket timeout itself.
      //
      // custom request socket timeout handle logic must follow these rules:
      //  1. Destroy socket first
      //  2. Must emit socket 'agentRemove' event tell agent remove socket
      //     from freeSockets list immediately.
      //     Otherise you may be get 'socket hang up' error when reuse
      //     free socket and timeout happen in the same time.
      if (listenerCount === 1) {
        const error = new Error('Socket timeout');
        error.code = 'ERR_SOCKET_TIMEOUT';
        error.timeout = getSocketTimeout(socket);
        // must manually call socket.end() or socket.destroy() to end the connection.
        // https://nodejs.org/dist/latest-v10.x/docs/api/net.html#net_socket_settimeout_timeout_callback
        socket.destroy(error);
        agent.removeSocket(socket, options);
        debug('%s destroy with timeout error', socket[SOCKET_NAME]);
      }
    }
  }
617911
function waitFor (event, listener, context, wait) {
    var timeout;
    if (!wait) {
        throw new Error("[FATAL] waitFor called without wait time");
    }
    var handler = function () {
        clearTimeout(timeout);
        listener.apply(context, arguments);
    };
    timeout = setTimeout(function () {
        this.off(event, handler, context);
        listener.call(context, "timeout");
    }.bind(this), wait);
    this.once(event, handler, context);
}
1243721
async def wait_closed(self):
        
        if self._server is None:
            raise RuntimeError('Server is not started')
        await self._server.wait_closed()
        if self._handlers:
            await asyncio.wait({h.wait_closed() for h in self._handlers},
                               loop=self._loop)
186518
public synchronized void waitForEnd()
	throws ServerException,
	       ClientException,
	       IOException {
        try {
            while(!isDone() && !hasError()) {
                wait();
            }
        } catch(InterruptedException e) {
            // break
        }
	    checkError();
    }
945494
function waitForRender() {
            var deferredRender = $q.defer();
            function wait() {
              if ($element.find("table:visible").length === 0) {
                $timeout(wait, 100);
              } else {
                deferredRender.resolve();
              }
            }

            $timeout(wait);
            return deferredRender.promise;
          }
454686
function onClose (ctx, err, val, cb) {
  // no callback no queue processing
  if (!_.isFunction(cb)) {
    ctx._heavy.stop();
    ctx._transport.close();
    if (err) {
      ctx.log.fatal(err);
      ctx.emit('error', err);
    }
    return;
  }

  // unsubscribe all active subscriptions
  ctx.removeAll();

  // wait until the client has flush all messages to nats
  ctx._transport.flush(() => {
    ctx._heavy.stop();
    // close NATS
    ctx._transport.close();

    if (err) {
      ctx.log.error(err);
      ctx.emit('error', err);
      if (_.isFunction(cb)) {
        cb(err);
      }
    } else {
      ctx.log.info(Constants.GRACEFULLY_SHUTDOWN);
      if (_.isFunction(cb)) {
        cb(null, val);
      }
    }
  });
}
138144
public void waitForExit() {
        if (shutdownHook != null) {
            synchronized (shutdownHookMonitor) {
                if (shutdownHook != null) {
                    synchronized (frameworkProcessMonitor) {
                        try {
                            frameworkProcess.waitFor();
                            shutdown();
                        // CHECKSTYLE:SKIP
                        } catch (Throwable e) {
                            shutdown();
                        }
                    }
                }
            }
        }
    }
685688
def _close(self):
        """"""
        self.client.stop()
        self.open = False
        self.waiting = False
1266793
function emit() {
  var self = this;
  (function execute() {
    try {
      if(self.i >= self.length) {
        self.emit('end');
      }
      else {
        var k = self.keys[self.i];
        self.emit('data', self.arr[k], k); 
        self.i++;
        if (!self.paused) nextTick(execute);
      }
    } catch (e) {
      self.emit('error', e);
      if (self._options.tolerant) {
        self.i++;
        if (!self.paused) nextTick(execute);
      }
      else {
        self.emit('end');
        self.readable = false;
      }
    }
  })();
}
448785
def waitUntilFinished(self):
        
        QtCore.QCoreApplication.processEvents()
        while self.isLoading():
            QtCore.QCoreApplication.processEvents()
624921
function () {

                var that = this,
                    paramHandler = this.params.handler,
                    params = util.mixin({}, this.params);

                //wrap the handler callbacks in a cancel check
                function handler(responseCode, data, ioArgs) {
                    that.xhr = ioArgs.xhr;
                    that.statusCode = that.xhr && !that.xhr.timedOut && that.xhr.status || 0;
                    if (that.canceled) {
                        logger.debug("Request [" + that.id + "] was canceled, not calling handler");
                    } else {
                        that.pending = false;
                        that.complete = true;
                        paramHandler(responseCode, data, ioArgs);
                    }
                }

                if (this.canceled) {
                    logger.debug("Request [" + that.id + "] was canceled, not executing");
                } else {
                    this.pending = true;
                    this.fn(util.mixin(params, {
                        handler: handler
                    }));
                }
            }
494931
def on_close(self):
        '''
        
        '''

        if self.id in self.funcserver.websocks:
            self.funcserver.websocks[self.id] = None
            ioloop = tornado.ioloop.IOLoop.instance()
            ioloop.add_callback(lambda: self.funcserver.websocks.pop(self.id, None))

        psession = self.funcserver.pysessions.get(self.pysession_id, None)
        if psession:
            psession['socks'].remove(self.id)
            if not psession['socks']:
                del self.funcserver.pysessions[self.pysession_id]
199103
def wait_event(self, filter: Callable[[T_Event], bool] = None) -> Awaitable[T_Event]:
        """"""
        return wait_event([self], filter)
640569
async def wait_async(self):
        
        if self.error:
            raise self.error
        if not self.running:
            raise ValueError("Unable to send until client has been started.")
        try:
            await self._handler.wait_async()
        except (errors.TokenExpired, errors.AuthenticationException):
            log.info("AsyncSender disconnected due to token error. Attempting reconnect.")
            await self.reconnect_async()
        except (errors.LinkDetach, errors.ConnectionClose) as shutdown:
            if shutdown.action.retry and self.auto_reconnect:
                log.info("AsyncSender detached. Attempting reconnect.")
                await self.reconnect_async()
            else:
                log.info("AsyncSender detached. Shutting down.")
                error = EventHubError(str(shutdown), shutdown)
                await self.close_async(exception=error)
                raise error
        except errors.MessageHandlerError as shutdown:
            if self.auto_reconnect:
                log.info("AsyncSender detached. Attempting reconnect.")
                await self.reconnect_async()
            else:
                log.info("AsyncSender detached. Shutting down.")
                error = EventHubError(str(shutdown), shutdown)
                await self.close_async(exception=error)
                raise error
        except Exception as e:
            log.info("Unexpected error occurred (%r).", e)
            raise EventHubError("Send failed: {}".format(e))