Wrapper for helper methods:
* Call the helper after resolving parameters (if any promises are passed)
* Wrap `options.fn` and `options.inverse` to return promises (if needed)
* Convert helper results markers if they are promises.
354086
function helperWrapper (fn, args) {
    var _this = this
    var options = args[args.length - 1]
    var hash = options.hash

    // "fn" and "inverse" return strings. They must be able to handle promises
    // just as the compiled template and partials
    options.fn = options.fn && wrap(options.fn, prepareAndResolveMarkers)
    options.inverse = options.inverse && wrap(options.inverse, prepareAndResolveMarkers)

    // If there are any promises in the helper args or in the hash,
    // the evaluation of the helper cannot start before these promises are resolved.
    var promisesInArgs = anyApplies(args, isPromiseAlike)
    var promisesInHash = anyApplies(values(hash), isPromiseAlike)

    if (!promisesInArgs && !promisesInHash) {
      // No promises in hash or args. Act a normal as possible.
      var result = fn.apply(_this, args)
      return isPromiseAlike(result) ? markers.asMarker(result) : result
    }

    var promise = deep(args).then(function (resolvedArgs) {
      // We need "markers", because we are in a new event-loop-cycle now.
      return prepareAndResolveMarkers(function () {
        return fn.apply(_this, resolvedArgs)
      })
    })
    return markers.asMarker(promise)
  }
1336567
function(convert, options) {
      var callback = options && 'process' in options ? options.process : options;

      if(typeof(callback) !== 'function') {
        return convert;
      }

      return function(string, options) {
        return callback(string, convert, options);
      }
    }
1284829
function wrapAsyncMethod(fn, ctx) {
    return function() {
        // Obtain function arguments
        var args = [].slice.call(arguments);

        // Return a thunkified function that receives a done callback
        return new Promise(function(resolve, reject) {
            // Add a custom callback to provided args
            args.push(function(err, result) {
                // Failed?
                if (err) {
                    return reject(err);
                }

                // Success
                resolve(result);
            });

            // Call original function
            fn.apply(ctx, args);
        });
    };
}
957995
function koifyHandler(fn, args, isErrHandler) {
	let fnResult;

	if (isGeneratorFunction(fn)) {
		fnResult = co(function* () {
			return yield* fn(...args);
		});
	} else {
		fnResult = fn(...args);
	}

	if (!isPromise(fnResult)) {
		return fnResult;
	}

	let req, res, next;

	if (isErrHandler) {
		req = args[1];
		res = args[2];
		next = args[3];
	} else {
		req = args[0];
		res = args[1];
		next = args[2];
	}

	return fnResult.then((result) => {
		// implicit 'next'
		if ((result === req) || (result === res)) {
			next();
		// explicit 'next'
		} else if ((isFunction(next) && (result === next)) || (result === ko.NEXT)) {
			next();
		} else if (result === ko.NEXT_ROUTE) {
			next('route');
		} else if (isError(result)) {
			next(result);
		} else if (result !== undefined) {
			if (isNumber(result)) {
				res.sendStatus(result);
			} else {
				res.send(result);
			}
		}

		// exposed for testing
		return result;
	}, (err) => {
		next(err);
		return err;
	});
}
335953
function(fn) {
  if (promisify.isPromise(fn))
    return fn;
  if (typeof fn !== 'function')
    return promisify.Promise.resolve(fn);
  return new Promise((resolve, reject) => {
    try {
      const o = fn();
      if (promisify.isPromise(o)) {
        o.then(v => resolve(v))
            .catch((e) => reject(e));
      } else resolve(o);
    } catch (e) {
      reject(e);
    }
  });
}
564522
function reversePromises (promises) {
    return promises.map(function (promise) {
      var d = $q.defer();
      promise.then(d.reject, d.resolve);
      return d.promise;
    });
  }
537714
function Promise(handler, parent) {
  var me = this;

  if (!(this instanceof Promise)) {
    throw new SyntaxError('Constructor must be called with the new operator');
  }

  if (typeof handler !== 'function') {
    throw new SyntaxError('Function parameter handler(resolve, reject) missing');
  }

  var _onSuccess = [];
  var _onFail = [];

  // status
  this.resolved = false;
  this.rejected = false;
  this.pending = true;

  /**
   * Process onSuccess and onFail callbacks: add them to the queue.
   * Once the promise is resolve, the function _promise is replace.
   * @param {Function} onSuccess
   * @param {Function} onFail
   * @private
   */
  var _process = function (onSuccess, onFail) {
    _onSuccess.push(onSuccess);
    _onFail.push(onFail);
  };

  /**
   * Add an onSuccess callback and optionally an onFail callback to the Promise
   * @param {Function} onSuccess
   * @param {Function} [onFail]
   * @returns {Promise} promise
   */
  this.then = function (onSuccess, onFail) {
    return new Promise(function (resolve, reject) {
      var s = onSuccess ? _then(onSuccess, resolve, reject) : resolve;
      var f = onFail    ? _then(onFail,    resolve, reject) : reject;

      _process(s, f);
    }, me);
  };

  /**
   * Resolve the promise
   * @param {*} result
   * @type {Function}
   */
  var _resolve = function (result) {
    // update status
    me.resolved = true;
    me.rejected = false;
    me.pending = false;

    _onSuccess.forEach(function (fn) {
      fn(result);
    });

    _process = function (onSuccess, onFail) {
      onSuccess(result);
    };

    _resolve = _reject = function () { };

    return me;
  };

  /**
   * Reject the promise
   * @param {Error} error
   * @type {Function}
   */
  var _reject = function (error) {
    // update status
    me.resolved = false;
    me.rejected = true;
    me.pending = false;

    _onFail.forEach(function (fn) {
      fn(error);
    });

    _process = function (onSuccess, onFail) {
      onFail(error);
    };

    _resolve = _reject = function () { }

    return me;
  };

  /**
   * Cancel te promise. This will reject the promise with a CancellationError
   * @returns {Promise} self
   */
  this.cancel = function () {
    if (parent) {
      parent.cancel();
    }
    else {
      _reject(new CancellationError());
    }

    return me;
  };

  /**
   * Set a timeout for the promise. If the promise is not resolved within
   * the time, the promise will be cancelled and a TimeoutError is thrown.
   * If the promise is resolved in time, the timeout is removed.
   * @param {number} delay     Delay in milliseconds
   * @returns {Promise} self
   */
  this.timeout = function (delay) {
    if (parent) {
      parent.timeout(delay);
    }
    else {
      var timer = setTimeout(function () {
        _reject(new TimeoutError('Promise timed out after ' + delay + ' ms'));
      }, delay);

      me.always(function () {
        clearTimeout(timer);
      });
    }

    return me;
  };

  // attach handler passing the resolve and reject functions
  handler(function (result) {
    _resolve(result);
  }, function (error) {
    _reject(error);
  });
}
53003
function call(method, key) {
    if (!exports.results.has(method))
        create(method); // create as needed
    const methodCache = exports.results.get(method);
    let callResults;
    if (methodCache.has(key)) {
        log_1.logger.debug(`[${method}] Calling (cached): ${key}`);
        // return from cache if key has been used on method before
        callResults = methodCache.get(key);
    }
    else {
        // call and cache for next time, returning results
        log_1.logger.debug(`[${method}] Calling (caching): ${key}`);
        callResults = exports.instance.call(method, key).result;
        methodCache.set(key, callResults);
    }
    return Promise.resolve(callResults);
}
75512
function wrapParsePromise(promise, parsePromise) {
      ['_rejected', '_rejectedCallbacks', '_resolved', '_resolvedCallbacks', '_result', 'reject', 'resolve']
        .forEach(function (prop) {
          promise[prop] = parsePromise[prop];
        });

      ['_continueWith', '_thenRunCallbacks', 'always', 'done', 'fail'].forEach(function (method) {
        promise[method] = wrap(parsePromise[method]);
      });

      ['then', 'catch'].forEach(function (method) {
        var func = promise[method];
        promise[method] = function wrappedAngularPromise() {
          var args = Array.prototype.slice.call(arguments, 0);
          var promise = func.apply(this, args);
          wrapParsePromise(promise, parsePromise);
          return promise;
        };
      });

      return promise;
    }
171244
function promisify(op) {
    var args = slice.call(arguments, 1);
    return new Promise(function(resolver) {
      op.apply(null, args.concat(function(err, value) {
        if(err) {
          resolver.reject(err);
        }
        else {
          resolver.resolve(value);
        }
      }));
    });
  }
195838
function withPromise(callback, {raf = false} = {}) {
  return new Promise((resolve, reject) => {
    if (raf) {
      requestAnimationFrame(() => {
        callback(resolve, reject);
      });
    } else {
      callback(resolve, reject);
    }
  });
}
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);
    }
  }
279801
function Promise(resolver) {
      if (!isFunction(resolver)) {
        throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
      }

      if (!(this instanceof Promise)) {
        throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
      }

      this._subscribers = [];

      invokeResolver(resolver, this);
    }
444234
function()
    {
        if (this._join.length) {

            var results = this._results;

            // Functions we need to call, that return a promise, for the value
            // we're recieving after subsequent joins
            var joins = [];

            this._join.forEach(function(join) {

                var f = function(outer) {
                    var inner = join.inner.toArray();

                    return inner.then(function(inner) {
                        var next = [];
                        outer.forEach(function(o) {
                            var oKey = o[join.outerKey];

                            // find the corresponding thing
                            var i = _(inner).find(function(i) {
                                return i[join.innerKey] == oKey;
                            });

                            if (i)
                                next.push(join.selector(o, i));

                        });
                        return next;
                    });
                };

                joins.push(f);
            });

            // Execute all of the joins, in order, feeding the result into the
            // next join. When they all are done, complete the promise for this
            // result
            return joins.reduce(Q.when, Q(results)).then(function(last) {
                return last;
            });

        } else {
            return Q(this._results);
        }
    }
561714
def hint(invertible=True, callable=None, **hints):
    

    def wrapper(fn):
        # Hang hints on fn.
        fn.hints = hints
        fn.hinting_invertible = invertible
        fn.hinting_callable = callable
        return fn

    return wrapper
207212
function next( ret ) {
            if( ret.done ) {
                return resolve( ret.value );
            }
            var value = toPromise.call( ctx, ret.value );
            if( value && isPromise( value ) ) {
                return value.then( onFulfilled, onRejected );
            }
            return onRejected( new TypeError( 'You may only yield a function, promise, generator, array, or object, '
                                              + 'but the following object was passed: "' + String( ret.value )
                                              + '"' ) );
        }
469273
function resolve(promise) {
    var method = promise.state === FULFILLED ? 'onFulfilled' : 'onRejected';
    var arg = method === 'onFulfilled' ? promise.value : promise.reason;
    var handler, value;

    nextTick(function() {
      var isPromise;

      while (promise.handlers[0]) {
        handler = promise.handlers.shift();

        try {
          value = handler[method](arg);

          // Handle "thenables" as well as Promises
          isPromise = value instanceof Promise || value && isFunc(value.then);

          if (isPromise) {
            value.then(function(value) { fulfill(handler.promise, value); },
                       function(reason) { reject(handler.promise, reason); });
          } else {
            fulfill(handler.promise, value);
          }
        } catch(err) {
          reject(handler.promise, err);
        }
      }
    });

    return promise;
  }