Wraps an async object with co-friendly functions
481986
function wrapAsync() {
    // Traverse async methods
    for (var fn in async) {
        // Promisify the method
        async[fn] = wrapAsyncMethod(async[fn], async);
    }

    // Return co-friendly async object
    return async;
}
1104101
def asyncthread(func):
    ''
    @functools.wraps(func)
    def _execAsync(*args, **kwargs):
        return vd().execAsync(func, *args, **kwargs)
    return _execAsync
24734
async function emitAsync (eventName, ...args) {
  // using a copy to avoid error when listener array changed
  let listeners = this.listeners(eventName)
  for (let i = 0; i < listeners.length; i++) {
    let fn = listeners[i]
    let obj = fn(...args)
    if (!!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function') obj = await obj
    if (obj !== undefined) return obj
  }
}
811920
function makeAsync(cb) {
    return function () {
        var args = arguments;
        process.nextTick(function () {
            cb.apply(null, args);
        });
    };
}
675515
function contentsAsync(file, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {};
  }

  if (typeof cb !== 'function') {
    throw new TypeError('expected a callback function');
  }

  if (!utils.isObject(file)) {
    cb(new TypeError('expected file to be an object'));
    return;
  }

  contentsSync(file, options);
  cb(null, file);
}
284281
function runAsync(context, func, callback)
{
  var result
    , requiresContext = isArrowFunction(func)
    ;

  if (requiresContext)
  {
    result = func.call(null, context, callback);
  }
  else
  {
    result = func.call(context, callback);
  }

  return result;
}
501972
function fromAsync(fn) {
  return new ReadableStream({
    pull: async controller => {
      try {
        controller.enqueue(await fn());
        controller.close();
      } catch(e) {
        controller.error(e);
      }
    }
  });
}
537211
public static AsyncCallback<String> wrapCallback(final JavaScriptObject func) {

        return new AsyncCallback<String>() {

            public void onFailure(Throwable caught) {

                // TODO Auto-generated method stub

            }

            public void onSuccess(String result) {

                callWithString(func, result);
            }

        };
    }
700569
function wrap(fn) {
  // Error handling middleware
  if (fn.length === 4) {
    return async function wrappedErrorHandler(error, req, res, next) {
      next = _once(next);
      try {
        await fn(error, req, res, next);
        res.headersSent ? null : next();
      } catch(err) {
        res.headersSent ? null : next(err);
      }
    };
  }

  return async function wrappedMiddleware(req, res, next) {
    next = _once(next);
    try {
      await fn(req, res, next);
      res.headersSent ? null : next();
    } catch(err) {
      res.headersSent ? null : next(err);
    }
  };
}
697202
def build_sink_async(coro=None, *, mode=None, unpack: bool = False):
    
    _mode = mode

    def _build_sink_async(coro):
        @wraps(coro)
        def _wrapper(*args, mode=None, **kwargs) -> SinkAsync:
            if 'unpack' in kwargs:
                raise TypeError('"unpack" has to be defined by decorator')
            if mode is None:
                mode = MODE.CONCURRENT if _mode is None else _mode
            return SinkAsync(coro, *args, mode=mode, unpack=unpack, **kwargs)
        return _wrapper

    if coro:
        return _build_sink_async(coro)

    return _build_sink_async
869289
def encode_async_options(async):
    """"""
    options = copy.deepcopy(async._options)

    options['_type'] = reference_to_path(async.__class__)

    # JSON don't like datetimes.
    eta = options.get('task_args', {}).get('eta')
    if eta:
        options['task_args']['eta'] = time.mktime(eta.timetuple())

    callbacks = async._options.get('callbacks')
    if callbacks:
        options['callbacks'] = encode_callbacks(callbacks)

    if '_context_checker' in options:
        _checker = options.pop('_context_checker')
        options['__context_checker'] = reference_to_path(_checker)

    if '_process_results' in options:
        _processor = options.pop('_process_results')
        options['__process_results'] = reference_to_path(_processor)

    return options
406364
function wrap (func) {
  return () => new Promise((resolve, reject) => {
    func()
      .then(x => resolve(x))
      .catch(err => {
        let status = _get(err, 'response.status')
        let text = _get(err, 'content.text')

        if (status || text) {
          console.warn(`API error: ${text} (${status})`)
          return resolve(null)
        }

        reject(err)
      })
  })
}
541929
function _makePartialAsync(func, asyncFn, syncFn) {
  
  // Return from cache
  var out,cached = this.cache[func.id];
  if (cached instanceof Function) return cached;

  if (func.async) {
    // Async function
    out = this.cache[func.relPath] = asyncFn;
  } else {
    // Sync function
    out = this.cache[func.relPath] = syncFn;
  }
  
  return out;

}
684116
function async (f, args) {
    new Promise(invoke).then(function asyncFulfill () {
      return f.apply(null, args);
    });
  }
597983
def coerce_to_synchronous(func):
    '''
    
    '''
    if inspect.iscoroutinefunction(func):
        @functools.wraps(func)
        def sync_wrapper(*args, **kwargs):
            loop = asyncio.get_event_loop()
            try:
                loop.run_until_complete(func(*args, **kwargs))
            finally:
                loop.close()
        return sync_wrapper
    return func
935356
function async(func)
{
  function wrapper()
  {
    var context = this;
    var args    = arguments;
    process.nextTick(function()
    {
      func.apply(context, args);
    });
  }

  return wrapper;
}
905175
def wrap_apply_async(apply_async_func):
    """"""

    def call(self, func, args=(), kwds={}, **kwargs):
        wrapped_func = wrap_task_func(func)
        _tracer = execution_context.get_opencensus_tracer()
        propagator = binary_format.BinaryFormatPropagator()

        wrapped_kwargs = {}
        wrapped_kwargs["span_context_binary"] = propagator.to_header(
            _tracer.span_context
        )
        wrapped_kwargs["kwds"] = kwds
        wrapped_kwargs["sampler"] = _tracer.sampler
        wrapped_kwargs["exporter"] = _tracer.exporter
        wrapped_kwargs["propagator"] = _tracer.propagator

        return apply_async_func(
            self, wrapped_func, args=args, kwds=wrapped_kwargs, **kwargs
        )

    return call