Return a wrapped handler function for the given function, which checks whether a synchronous request is currently in progress.
198392
function wrapHandler(fnHandler) {
						var fnWrappedHandler = function(oEvent) {
							// The ready state at the time the event is occurring needs to
							// be preserved, to restore it when the handler is called delayed
							var iCurrentState = oXHR.readyState;
							function callHandler() {
								iReadyState = iCurrentState;
								// Only if the event has not been removed in the meantime
								// the handler needs to be called after the timeout
								if (fnWrappedHandler.active) {
									return fnHandler.call(oProxy, oEvent);
								}
							}
							// If this is an asynchronous request and a sync request is ongoing,
							// the execution of all following handler calls needs to be delayed
							if (!bSync && bSyncRequestOngoing) {
								bDelay = true;
							}
							if (bDelay) {
								_timeout(callHandler, 0);
								return true;
							}
							return callHandler();
						};
						fnHandler.wrappedHandler = fnWrappedHandler;
						fnWrappedHandler.active = true;
						return fnWrappedHandler;
					}
171403
def ensure_async(function_original):
    

    def wrapper(*args, **kwargs):
        try:
            result = function_original(*args, **kwargs)
            if isinstance(result, Deferred):
                return result
            d = Deferred()
            d.callback(result)
            return d
        except:
            return fail()

    return wrapper
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
                    }));
                }
            }
893733
def synchronized(func):  # pylint: disable=invalid-name
  """"""
  @functools.wraps(func)
  def synchronized_method(self, *args, **kwargs):
    """Wrapper to return."""
    if not hasattr(self, '_lock'):
      if func.__name__ in type(self).__dict__:
        hint = ''
      else:
        hint = (' Might be missing call to super in %s.__init__?' %
                type(self).__name__)
      raise RuntimeError('Can\'t synchronize method `%s` of %s without '
                         'attribute `_lock`.%s' %
                         (func.__name__, type(self).__name__, hint))
    with self._lock:  # pylint: disable=protected-access
      return func(self, *args, **kwargs)
  return synchronized_method
129929
def run_task(func):
    

    def _wrapped(*a, **k):
        loop = asyncio.get_event_loop()
        return loop.run_until_complete(func(*a, **k))

    return _wrapped
1173104
function getHandler(fn) {
    if (isFunction(fn) && fn.actionHandler) {
        return function (req, res, next) {
            terminateMethods.map(function (method) {
                res[method] = getWrappedResponse(res[method]);
            });
            callHandler(fn, req, res, next);
        };
    } else {
        return fn;
    }
}
862328
def avoid_parallel_execution(func):
    
    def func_wrapper(*args, **kwargs):
        if not getattr(func, "currently_executing", False):
            func.currently_executing = True
            try:
                return func(*args, **kwargs)
            finally:
                func.currently_executing = False
        else:
            logger.verbose("Avoid parallel execution of function {}".format(func))
    return func_wrapper
589856
def _function_handler(function, args, kwargs, pipe):
    """"""
    signal.signal(signal.SIGINT, signal.SIG_IGN)

    result = process_execute(function, *args, **kwargs)

    send_result(pipe, result)
946682
def thread(function):
    
    @wraps(function)
    def wrapper(*args, **kwargs):
        future = Future()

        launch_thread(_function_handler, function, args, kwargs, future)

        return future

    return wrapper
481875
function awaitFunction(fn) {
  return (req, res, next) => {
    Promise.resolve(fn(req, res, next)).catch(next);
  };
}
624144
def sync(lock):
    
    def sync(f):
        @wraps(f)
        def new_function(*args, **kwargs):
            lock.acquire()
            try:
                return f(*args, **kwargs)
            finally:
                lock.release()
        return new_function
    return sync
555159
function Promise(callback, handler) {
			// The `handler` variable points to the function that will
			// 1) handle a .then(resolved, rejected) call
			// 2) handle a resolve or reject call (if the first argument === `is`)
			// Before 2), `handler` holds a queue of callbacks.
			// After 2), `handler` is a finalized .then handler.
			handler = function pendingHandler(resolved, rejected, value, queue, then, i) {
				queue = pendingHandler.q;

				// Case 1) handle a .then(resolved, rejected) call
				if (resolved != is) {
					return Promise(function (resolve, reject) {
						queue.push({ p: this, r: resolve, j: reject, 1: resolved, 0: rejected });
					});
				}

				// Case 2) handle a resolve or reject call
				// (`resolved` === `is` acts as a sentinel)
				// The actual function signature is
				// .re[ject|solve](<is>, success, value)

				// Check if the value is a promise and try to obtain its `then` method
				if (value && (is(func, value) | is(obj, value))) {
					try { then = value.then; }
					catch (reason) { rejected = 0; value = reason; }
				}
				// If the value is a promise, take over its state
				if (is(func, then)) {
					function valueHandler(resolved) {
						return function (value) { then && (then = 0, pendingHandler(is, resolved, value)); };
					}
					try { then.call(value, valueHandler(1), rejected = valueHandler(0)); }
					catch (reason) { rejected(reason); }
				}
				// The value is not a promise; handle resolve/reject
				else {
					// Replace this handler with a finalized resolved/rejected handler
					handler = function (Resolved, Rejected) {
						// If the Resolved or Rejected parameter is not a function,
						// return the original promise (now stored in the `callback` variable)
						if (!is(func, (Resolved = rejected ? Resolved : Rejected)))
							return callback;
						// Otherwise, return a finalized promise, transforming the value with the function
						return Promise(function (resolve, reject) { finalize(this, resolve, reject, value, Resolved); });
					};
					// Resolve/reject pending callbacks
					i = 0;
					while (i < queue.length) {
						then = queue[i++];
						// If no callback, just resolve/reject the promise
						if (!is(func, resolved = then[rejected]))
							(rejected ? then.r : then.j)(value);
						// Otherwise, resolve/reject the promise with the result of the callback
						else
							finalize(then.p, then.r, then.j, value, resolved);
					}
				}
			};
			// The queue of pending callbacks; garbage-collected when handler is resolved/rejected
			handler.q = [];

			// Create and return the promise (reusing the callback variable)
			callback.call(callback = { then:    function (resolved, rejected) { return handler(resolved, rejected); },
					"catch": function (rejected)           { return handler(0,        rejected); } },
				function (value)  { handler(is, 1,  value); },
				function (reason) { handler(is, 0, reason); });
			return callback;
		}
1195415
def _handler(func):
    ""

    def _wrapped(*a, **k):
        r = func(*a, **k)
        if r is None: r = 0
        return r

    return staticmethod(_wrapped)
205185
function wrapHandler(handler) {
  return function (state, ...args) {
    return _.assign({}, state, handler(state, ...args));
  };
}
1347817
def wrap(function, *args, **kwargs):
    ''''''
    try:
        req = function(*args, **kwargs)
        logger.debug('Got %s: %s', req.status_code, req.content)
        if req.status_code == 200:
            return req
        else:
            raise ClientException(req.reason, req.content)
    except ClientException:
        raise
    except Exception as exc:
        raise ClientException(exc)
481051
def api(func):
    """"""
    @wraps(func)
    def decorated_function(*args, **kwargs):
        try:
            value = func(*args, **kwargs)
        except BaseException as e:
            value = {
                "status": "failed",
                "error": "Unkonwn error!"
            }
            flask.current_app.logger.error("Unkonwn error: %s" % str(e))
            flask.current_app.logger.exception(e)

        status = 200
        mimetype = 'application/json'
        content = json.dumps(value)
        callback = flask.request.args.get('callback', False)
        if callback:
            content = str(callback) + '(' + content + ')'
            mimetype = 'application/javascript'

        return flask.current_app.response_class(content, status=status, mimetype=mimetype)
    return decorated_function
734429
function responseHandler (res, next) {
  return function (err, message) {
    if (err || !message) {
      next(err);
    } else {
      res.send(message);
    }
  }
}