We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent debee84 commit fffed88Copy full SHA for fffed88
1 file changed
Promise.all.js
@@ -0,0 +1,26 @@
1
+const sleep = (duration) =>
2
+ new Promise((resolve) => setTimeout(() => resolve(duration), duration));
3
+
4
+async function all(list) {
5
+ return new Promise((res, rej) => {
6
+ let count = 0;
7
+ const result = [];
8
9
+ list.forEach((item) => {
10
+ Promise.resolve(item)
11
+ .then((data) => {
12
+ result.push(data);
13
+ count++;
14
15
+ if (count === list.length) {
16
+ res(result);
17
+ }
18
+ })
19
+ .catch(rej);
20
+ });
21
22
+}
23
24
+all([sleep(1000), sleep(2000), sleep(3000)]).then((res) => {
25
+ console.log(res);
26
+});
0 commit comments