Last active
December 5, 2015 08:20
-
-
Save piecyk/40b1ac8ae76c663b495f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function resolvePending(arrayOfPromises) { | |
| const d = $.Deferred(); | |
| let resolved = []; | |
| let rejected = []; | |
| const check = () => { | |
| if (resolved.length + rejected.length === arrayOfPromises.length) { | |
| rejected.length > 0 ? d.reject(rejected) : d.resolve(resolved); | |
| } | |
| }; | |
| $.each(arrayOfPromises, function(i, fn) { | |
| fn(). | |
| done(res => { | |
| resolved = resolved.concat(res); | |
| check(); | |
| }). | |
| fail(res => { | |
| rejected = rejected.concat(res); | |
| check(); | |
| }); | |
| }); | |
| return d; | |
| } | |
| function asyncThing() { | |
| //return promise | |
| } | |
| resolvePending([asyncThing, asyncThing, asyncThing]). | |
| then(function(resolved) { | |
| console.log(resolved); | |
| }). | |
| fail(function(rejected) { | |
| console.log(rejected); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment