Takes a function that returns a promise, and returns a wrapped version that
ensures that multiple invocations are serialized (only one at a time).
763093
function serialized(func) {
  var currentPromise = null;
  var wrapped = function() {
    var self = this;
    var args = arguments;
    if (currentPromise) {
      return currentPromise.fin(function() {
        return wrapped.apply(self, args);
      });
    }

    currentPromise = func.apply(self, args);
    
    currentPromise
    .fin(function() {
      currentPromise = null;
    })
    .eat();
    
    return currentPromise;
  };
  return wrapped;
}
46189
function Promise(fn) {
  if (typeof this !== 'object') {
    throw new TypeError('Promises must be constructed via new');
  }
  if (typeof fn !== 'function') {
    throw new TypeError('not a function');
  }
  this._37 = 0;
  this._12 = null;
  this._59 = [];
  if (fn === noop) return;
  doResolve(fn, this);
}
182413
async function repeatablePromise (initialAssumptions, assumptionsFromResult, promiseGenerator) {
    let promise = promiseGenerator(initialAssumptions);
    let result = await promise;
    let finalAssumptions = assumptionsFromResult(result);
    if (JSON.stringify(initialAssumptions) === JSON.stringify(finalAssumptions)) {
        return promise;
    } else {
        return promiseGenerator(finalAssumptions);
    }
}
472760
function (promise){
    		promise.success = function (fn) {
	            promise.then(fn);
	            return promise;
	        };

	        promise.error = function (fn) {
	            promise.then(null, fn);
	            return promise;
	        };
    	}
1357210
function rebuildAsPromise(_thisObject, name, fn) {
    // if is a regular function, that has an async correspondent also make it promiseable
    if (!isFunctionAsync(_thisObject, name, fn)) {
        return function() {
            var that = this,
                args = arguments;

            return blinkts.lang.promiseCode(function() {
                return fn.apply(that, args);
            });
        };
    }

    // if it's an async function, make it promiseable.
    return function() {
		var args = Array.prototype.slice.apply(arguments),
			that = this;

		return new blinkts.lang.Promise(function(fulfill, reject) {
			args.push(function(err, r) {
				if (err) {
					reject(err);
				}

				if (arguments.length > 2) { // if the callback received multiple arguments, put them into an array.
					fulfill(Array.prototype.slice.call(arguments, 1));
				} else {
					fulfill(r);
				}
			});

			try {
				var result = fn.apply(that, args);
			} catch (e) { // if the function failed, so we don't get a chance to get our callback called.
				reject(e);
			}
		});
    };
}
991247
public <R> Promise<R> zipPromise(final ListFunction<T, Promise<R>> fuc) {
        return new Promise<>(resolver -> {
            promises.then(promises1 -> {
                final ArrayList<T> res = new ArrayList<T>();
                for (int i = 0; i < promises1.length; i++) {
                    res.add(null);
                }
                final Boolean[] ended = new Boolean[promises1.length];

                for (int i = 0; i < promises1.length; i++) {
                    final int finalI = i;
                    promises1[i].then(t -> {
                        res.set(finalI, t);
                        ended[finalI] = true;

                        for (int i1 = 0; i1 < promises1.length; i1++) {
                            if (ended[i1] == null || !ended[i1]) {
                                return;
                            }
                        }

                        fuc.apply(res)
                                .pipeTo(resolver);
                    });
                    promises1[i].failure(e -> resolver.error(e));
                }

                if (promises1.length == 0) {
                    fuc.apply(res)
                            .pipeTo(resolver);
                }
            });
            promises.failure(e -> resolver.error(e));
        });
    }
275866
function promisify(func) {
        return function(str, options) {
            var result,
                deferred = q.defer(),
                promise = deferred.promise;

            if (!_.isFunction(func)) {
                deferred.reject();
            }
            else {
                result = func(str, options);

                if (_.isBoolean(result)) {
                    promise = handleBoolean(result, deferred);
                }
                else if (_.isFunction(result.then)) {
                    promise = result;
                }

            }
            return promise;
        };
    }
583109
function () {
		var that = this,
				independent, 
				dependencyNotRequired;
		
		promiseIndependent = this.saveFixturesFromArray(independentFixtures);
		promiseDelayedDependency = this.saveFixturesFromArray(delayedDependencyFixtures);
		
		promise = Q.all([ promiseIndependent, promiseDelayedDependency ])
			.then(function(models) {
				return that.saveFixturesFromArray(requiredDependencyFixtures);
			});
		
		return promise;
	}
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
511088
function serial(promises) {
    const results = [];

    return promises
        .reduce((chain, promise) =>
            chain.then(result => {
                results.push(result);
                return promise
            }), Promise.resolve())
        .then(result => {
            results.push(result);
            results.shift();
            return results;
        })
}
585614
function() {
		var that = this;
		return new Promise(function(resolve, reject) {
			that.resolve(function(err, val) {
				if (err) {
					reject(err);
				} else {
					resolve(val);
				}
			});
		});
	}
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;
}
276559
function Promise(o){
	var self = this;
	
        // object mixin
        if(o && typeof o === 'object'){
            for(var k in Promise.prototype)
		o[k] = Promise.prototype[k];
	    o._promise = {_chain:[]};

	    return o;
        }
	
	// create new instance
        if(!(this instanceof Promise))
            return new Promise(o);

	this._promise = {_chain: []};

        // use resolver callback
        if(typeof o === 'function') {
	    task(function(){
		var res = self.resolve.bind(self),
		    rej = self.reject.bind(self);
		o(res,rej);
	    });
        }
    }
1330346
function promisify(func) {
  return function promisified() {
    var args = Array.prototype.slice.call(arguments);
    var context = this;

    return new Promise(function(resolve, reject) {
      try {
        func.apply(context, args.concat(function(err, data) {
          if (err) {
            return reject(err);
          }

          resolve(data);
        }));
      } catch(err) {
        reject(err);
      }
    });
  };
}
1245336
function() {
		var instance = this.scraper.clone(),
			promise = new ScraperPromise(instance);
		promise._setPromises(this.promises);
		promise.done(this.doneCallback);
		promise.catch(this.errorCallback);
		return promise;
	}
142578
function createJqCompatiblePromise(fnPromise, oContext) {

		var oOriginalPromise = new Promise(fnPromise);

		// if no context is set, use the promise as context
		oContext = oContext || oOriginalPromise;

		// track the promise state (for state method)
		var bResolved = false, bRejected = false;

		oOriginalPromise.then(function(v) {
			bResolved = true;
			return v;
		}, function(e) {
			bRejected = true;
			throw e;
		});

		// save original standard methods
		var mOriginalMethods = {
				then: oOriginalPromise.then,
				"catch": oOriginalPromise["catch"]
		};

		function makePromiseJqCompatible(oPromise) {

			// Wrap standard promise methods

			oPromise.then = function(fnSuccessCallback, fnErrorCallback) {
				// TODO: handle multiple arguments + array of callbacks
				var aArgs = [ wrapCallback(fnSuccessCallback, oContext), wrapCallback(fnErrorCallback, oContext) ];
				return makePromiseJqCompatible(mOriginalMethods.then.apply(oPromise, aArgs), oContext);
			};
			oPromise["catch"] = function(fnCallback) {
				var aArgs = [ wrapCallback(fnCallback, oContext) ];
				return makePromiseJqCompatible(mOriginalMethods["catch"].apply(oPromise, aArgs), oContext);
			};

			// Map jQuery Promise methods to standard methods and add a deprecation warning

			[ {
				jq: "done",
				es6: "then"
			}, {
				jq: "fail",
				es6: "catch"
			}, {
				jq: "always",
				es6: "then"
			}].forEach(function(mConfig) {
				oPromise[mConfig.jq] = function() {
					printJqPromiseDeprecationWarning(mConfig.jq);
					var oReturnPromise = null;
					Array.prototype.concat.apply([], arguments).forEach(function(fnCallback) {
						var fnWrappedCallback = wrapCallback(fnCallback, oContext);
						var fnFinalCallback = function(v) {
							fnWrappedCallback.apply(this, arguments);
							return v;
						};
						var aArgs = [ fnFinalCallback ];
						if (mConfig.jq === "always") {
							// use same callback for success / error handler
							aArgs.push(fnFinalCallback);
						}
						if (!oReturnPromise) {
							oReturnPromise = mOriginalMethods[mConfig.es6].apply(oPromise, aArgs);
						} else {
							oReturnPromise = oReturnPromise[mConfig.es6].apply(oReturnPromise, aArgs);
						}
					});
					return makePromiseJqCompatible(oReturnPromise, oContext);
				};
			});
			oPromise.pipe = function(fnDoneCallback, fnFailCallback) {
				printJqPromiseDeprecationWarning("pipe");
				return oPromise.then(fnDoneCallback, fnFailCallback);
			};
			oPromise.state = function() {
				printJqPromiseDeprecationWarning("state");
				if (bResolved) {
					return "resolved";
				} else if (bRejected) {
					return "rejected";
				} else {
					return "pending";
				}
			};

			return oPromise;
		}

		return makePromiseJqCompatible(oOriginalPromise);

	}
1001703
function generatePromise (promiseFunctions, contraMethod, silenceErrors) {
  return new Promise((resolve, reject) => {
    // Generate a function that executes the promise function and
    // calls back in a way that the contra library requires
    for (let i in promiseFunctions) {
      let promiseFunction = promiseFunctions[i]

      if (!isFunction(promiseFunction)) {
        return reject(new Error('One of the supplied promise functions is not a function'))
      }

      promiseFunctions[i] = (contraCallback) => {
        promiseFunction()
          .then(data => contraCallback(null, data))
          .catch(err => silenceErrors ? contraCallback(null, null) : contraCallback(err))
      }
    }

    contraMethod(promiseFunctions, (err, results) => {
      if (err) return reject(err)
      resolve(results)
    })
  })
}