// @ts-nocheck import e = require("../_base/array"); import t = require("../_base/lang"); import i = require("../Deferred"); import n = require("../when"); type Promise = typeof import("dojo/promise/Promise"); var o = e.some; /** * Takes multiple promises and returns a new promise that is fulfilled * when all promises have been resolved or one has been rejected. * @param objectOrArray The promise will be fulfilled with a list of results if invoked with an * array, or an object of results when passed an object (using the same * keys). If passed neither an object or array it is resolved with an * undefined value. */ function all(array: DojoJS.Thenable[]): Promise; function all(object: { [name: string]: DojoJS.Thenable }): Promise<{ [name: string]: T }>; function all(array: DojoJS.Thenable[]): Promise; function all(object: { [name: string]: DojoJS.Thenable }): Promise<{ [name: string]: any }>; function all(object: { [name: string]: DojoJS.Thenable } | DojoJS.Thenable[]): Promise<{ [name: string]: T }> { var a, s, r; t.isArray(object) ? (s = object) : object && "object" == typeof object && (a = object); var l = []; if (a) { s = []; for (var d in a) if (Object.hasOwnProperty.call(a, d)) { l.push(d); s.push(a[d]); } r = {}; } else s && (r = []); if (!s || !s.length) return new i().resolve(r); var c = new i(); c.promise.always(function () { r = l = null; }); var h = s.length; o(s, function (e, t) { a || l.push(t); n( e, function (e) { if (!c.isFulfilled()) { r[l[t]] = e; 0 == --h && c.resolve(r); } }, c.reject ); return c.isFulfilled(); }); return c.promise; }; export = all;