Return a promise-based version of a callback-based async method.
968541
function(func, resolves = false){
    if(typeof resolves !== 'boolean' && typeof resolves !== 'number' && resolves != 'all'){
      throw new Error('Invalid value submitted for \'resolves\' argument.')
    }
    return function(){
      return new Promise((resolve, reject)=>{
        var params = [...arguments, function(...args){

          //check for error hooks
          var error = false;
          for(let arg of args){
            if(arg instanceof Error){
              error = arg;
              break;
            }
          }

          if(error){
            reject(error)
          }else{
            switch(resolves){
              case false:
                resolve(arguments.length == 1 ? arguments[0] : arguments[1])
                break;
              case true:
                resolve(true)
                break;
              case 'all':
                resolve(args)
                break;
              default:
                resolve(args[resolve])
            }
          }
        }]
        func.apply(null, params)
      })
    }
  }
56899
function resolveAsync(p, base, root) {
  if (!path.isAbsolute(p)) {
    return new Promise(function(r, j) {
      resolve(forceRelative(p), {
        basedir: path.resolve(root, base)
      }, function(err, res) {
        if (err) {
          j(err);
        } else {
          r(res);
        }
      });
    });

  } else {

    return Promise.resolve(p);
  }
}
1165987
function(callback) {
                var deferred = $q.defer();

                this.isAvailable().then(function() {
                    window.ThreeDeeTouch.watchForceTouches(callback);
                    deferred.resolve(true);
                },
                function(err) {
                    deferred.reject(err);
                });

                return deferred.promise;
            }
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;
}
793646
function waitAll() {
    return new Promise(function (resolved) {
        if (currentCount === 0 && remainedTasks.length === 0) {
            resolved();
        } else {
            waitAllCallbacks.push(resolved);
        }
    });
}
1078193
def wrap_callback(function):
        """"""

        @wraps(function)
        def wrapped(task):
            task._callback_result = function(task)
            return task._callback_result

        return wrapped
472760
function (promise){
    		promise.success = function (fn) {
	            promise.then(fn);
	            return promise;
	        };

	        promise.error = function (fn) {
	            promise.then(null, fn);
	            return promise;
	        };
    	}
767832
function awaitFunctionCall() {
                let func;
                const promise = new Promise((resolve, reject) => {
                    func = function(...args) {
                        resolve(args);
                        return new Promise((resolve, reject) => {
                            // give us some time to process the result before
                            // continuing
                            global.setTimeout(resolve, 1);
                        });
                    };
                });
                return {func, promise};
            }
111055
function asyncAdd (a, b) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      resolve(a + b);
    }, 1000);
  });
}
239191
function waitForReady (method) {
  return function fetchSync_readyWrapper (...args) {
    if (hasStartedInit) return ready.promise.then(() => method(...args))
    throw new Error('initialise first with fetchSync.init()')
  }
}
365751
function(asyncFunc, callback) {
  asyncFunc(function(err, buffer) {
    if(callback) {
      callback(err, buffer.toHex().toString());
    }
  });
}
1232981
def async_func(self, function):
        """"""

        @wraps(function)
        def wrapped(*args, **kwargs):
            return self.submit(function, *args, **kwargs)

        return wrapped
1187611
def _send(self, method, **parameters):
        """"""
        msg = {
            'index': self._calls,
            'method': method,
        }
        msg.update(parameters)

        promise = SimplePromise()
        self._callbacks[self._calls] = promise

        self._calls += 1
        self._comm.send(msg)

        return promise
179056
function (task, argument, callback) {
        var self = this;
        var queueArgument = {
            task: task,
            argument: argument
        };

        return promiseOrCallback(callback, function (resolve, reject) {
            self.taskQueue.push(queueArgument, function (error, result) {
                if (error) {
                    reject(error);
                } else {
                    resolve(result);
                }
            });
        });
    }
313946
function extend_if_promise(methods, ret) {
		if(ret && ret.then) {                                 // Check if return value is promise compatible
			return extend.promise(methods, ret);              // ..and if so, extend it, too.
		}
		return ret;                                           // ..and if not, return the same value.
	}
91056
function promisedRequest(params, callback) {
  var deferred = Promise.defer();
  var req;
  var createRequest = function() {
    if (!req) {
      req = request(params, function(err, response) {
        if (err) {
          deferred.reject(err);
        } else {
          deferred.resolve(response);
        }
      });
    }
    return req;
  };
  return streamify(deferred.promise, createRequest).thenCall(callback);
}
147482
function(asyncRes, callback) {
			var jobId = asyncRes.jobID

			if (!jobId) return callback(null, asyncRes)
			else if (IODOpts.getResults) {
				IOD.result({
					jobId: jobId,
					majorVersion: IODOpts.majorVersion,
					retries: 3
				}, callback)
			}
			else {
				callback(null, asyncRes)
				pollUntilDone(jobId)
			}

		}