Take an iterable of Promises and invoke them serially, otherwise identical
to the `Promise.all` static method.

@param {Promise[]} promises
@return {Promise}
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;
        })
}
297862
function forEachPromise(items, fn) {
  return items.reduce(
    (promise, item) => promise
      .then(() => fn(item))
      .catch((error) => { throw error; }),
    Promise.resolve()
  );
}
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);
	    });
        }
    }
1095110
function(arr, iterator) {
			if (typeof iterator !== 'function') return apiRejection('iterator must be a function');

			var self = this;
			var i = 0;
			return Promise.resolve().then(function iterate() {
				if (i == arr.length) return;

				return Promise.resolve(iterator.call(self, arr[i]))
				.then(function(result) {
					if (result !== undefined) return result;

					i++;
					return iterate();
				});
			});
		}
156087
function all(iterable){
    var C          = this
      , capability = newPromiseCapability(C)
      , resolve    = capability.resolve
      , reject     = capability.reject;
    var abrupt = perform(function(){
      var values    = []
        , index     = 0
        , remaining = 1;
      _forOf(iterable, false, function(promise){
        var $index        = index++
          , alreadyCalled = false;
        values.push(undefined);
        remaining++;
        C.resolve(promise).then(function(value){
          if(alreadyCalled)return;
          alreadyCalled  = true;
          values[$index] = value;
          --remaining || resolve(values);
        }, reject);
      });
      --remaining || resolve(values);
    });
    if(abrupt)reject(abrupt.error);
    return capability.promise;
  }
668372
function synchronous(promiseFactory) {
  return function () {
    var promise = queue.then(promiseFactory);
    queue = promise.catch(noop); // squelch
    return promise;
  };
}
730224
@SafeVarargs
    public static <T> PromisesArray<T> of(T... items) {
        ArrayList<Promise<T>> res = new ArrayList<>();
        for (T t : items) {
            res.add(Promise.success(t));
        }
        final Promise[] promises = res.toArray(new Promise[res.size()]);
        return new PromisesArray<>((PromiseFunc<Promise<T>[]>) executor -> {
            executor.result(promises);
        });
    }
1296495
function (iter) {
      function continuer(verb, arg) {
        var result;
        try {
          result = iter[verb](arg);
        } catch (err) {
          return Promise.reject(err);
        }
        if (result.done) {
          return result.value;
        } else {
          return Promise.resolve(result.value).then(onFulfilled, onRejected);
        }
      }
      var onFulfilled = continuer.bind(continuer, "next");
      var onRejected = continuer.bind(continuer, "throw");
      return onFulfilled();
    }
1148327
public static <T> TracedParallelBatch<T> of(Iterable<? extends Promise<T>> promises) {
    return new TracedParallelBatch<>(promises);
  }
656879
function (promise, i) {
            var self = this;
            promise.then(
                function () {
                    var args = argsToArray(arguments);
                    args.unshift(i);
                    spreadArgs(self.callback, args, self);
                    promise = i = self = null;
                },
                function () {
                    var args = argsToArray(arguments);
                    args.unshift(i);
                    spreadArgs(self.errback, args, self);
                    promise = i = self = null;
                });
        }
642438
function asPromise (fn) {
  return new Promise((resolve, reject) => {
    fn((err, result) => {
      if (err) {
        return reject(err)
      }
      resolve(result)
    })
  })
}
1293763
@Contract(pure = true)
	@NotNull
	public static <T> Promise<T> timeout(@NotNull Promise<T> promise, long delay) {
		if (promise.isComplete()) return promise;
		if (delay <= 0) return Promise.ofException(TIMEOUT_EXCEPTION);
		return promise.next(new NextPromise<T, T>() {
			@Nullable ScheduledRunnable schedule = getCurrentEventloop()
					.delay(delay,
							() -> {
								schedule = null;
								tryCompleteExceptionally(TIMEOUT_EXCEPTION);
							});

			@Override
			public void accept(T result, @Nullable Throwable e) {
				if (schedule != null) {
					schedule.cancel();
					schedule = null;
				}
				if (e == null) {
					tryComplete(result);
				} else {
					tryCompleteExceptionally(e);
				}
			}
		});
	}
56776
function evaluatePromise() {
  var promise = kew.defer();
  var args = utils.toArray(arguments);
  args.push(promise.makeNodeResolver());
  /*jshint validthis:true */
  evaluate.apply(this, args);
  return promise;
}
298728
@Contract(pure = true)
	@NotNull
	public static Promise<Void> all(@NotNull Promise<?> promise1, @NotNull Promise<?> promise2) {
		return promise1.both(promise2);
	}
237212
function makePromise(fn) {
	return function() {
		var args = Array.prototype.slice.call(arguments);
		if (hasCallback(args)) {
			// argument list has callback, so call method with callback
			return callCallback(fn, args);
		} else {
			// no callback, call method with promises
			return callPromise(fn, args);
		}
	}
}
1142602
function promiseMiddleware (request, response, middleware) {
  return new promiseMiddleware.Promise(function (resolve, reject) {
    middleware(request, response, function next (error) {
      return error ? reject(error) : resolve()
    })
  })
}
412953
function race(iterable) {
    var C = this;
    var capability = newPromiseCapability(C);
    var reject = capability.reject;
    var result = perform(function () {
      var $promiseResolve = aFunction(C.resolve);
      iterate(iterable, function (promise) {
        $promiseResolve.call(C, promise).then(capability.resolve, reject);
      });
    });
    if (result.error) reject(result.value);
    return capability.promise;
  }