Created
December 12, 2017 10:54
-
-
Save davidcostadev/89cdccc8a92760c9cd6e138910e6c087 to your computer and use it in GitHub Desktop.
array de Promises
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
| export function pilha({ data, cursor, promise, results }) { | |
| return new Promise((resolve, reject) => { | |
| cursor = typeof cursor !== 'undefined' ? cursor : 0 | |
| results = typeof results !== 'undefined' ? results : [] | |
| promise(data[cursor]).then((result) => { | |
| cursor += 1 | |
| results.push(result) | |
| if (cursor < data.length) { | |
| pilha({ | |
| data, | |
| cursor, | |
| promise, | |
| results, | |
| }).then((pipe) => { | |
| resolve(pipe) | |
| }).catch((err) => { | |
| console.error('pilha', 'catch1') | |
| resolve([]) | |
| }) | |
| } else { | |
| resolve(results) | |
| } | |
| }).catch((err) => { | |
| console.error('pilha', 'catch2') | |
| resolve([]) | |
| }) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment