You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- The async functions can be executed in parallel using the loop and can be tracked for completion with a counter
255
255
- The callback function can be sent to the async functions and the results will be stored in the array which will be returned after the completion of all
256
256
257
-
```js
257
+
```js copy
258
258
functionasyncParallel(asyncFuncArr, callback) {
259
259
constresultArr=newArray(asyncFuncArr.length);
260
260
let resultCounter =0;
@@ -283,7 +283,7 @@ function asyncParallel(asyncFuncArr, callback) {
283
283
-`then` method on Promise also returns a promise which can be used to perform `then` on the returned promise
284
284
- The errors in promise / promise chaining can be handled with the error callback for each promise when it settles or with a generic catch block
285
285
286
-
```js
286
+
```js copy
287
287
asyncFunc1().then(
288
288
() => {
289
289
console.log("Completed async1");
@@ -311,7 +311,7 @@ asyncFunc1().then(
311
311
);
312
312
```
313
313
314
-
```js
314
+
```js copy
315
315
asyncFunc1()
316
316
.then(asyncFunc2)
317
317
.then(asyncFunc3)
@@ -334,7 +334,7 @@ If `then` method has a return statement which is a promise then it will be consi
334
334
335
335
- Async function with `await` for each promise can be used to execute in sequence
336
336
337
-
```js
337
+
```js copy
338
338
+asyncfunctionexecutor(){
339
339
try{
340
340
awaitasyncFunc1();
@@ -355,7 +355,7 @@ If `then` method has a return statement which is a promise then it will be consi
355
355
- The promise which gets rejected will invoke the 2nd function argument to `then` handler
356
356
- The failure handler will receive the error and continue with next execution which will not propagate failures
357
357
358
-
```js
358
+
```js copy
359
359
async1()
360
360
.then(
361
361
() => {
@@ -392,7 +392,7 @@ async1()
392
392
- Unlike promises, `try-catch` block can be used on async functions
393
393
- `catch` block for each asynchronous function can be used to catch errors and continue with next execution which will not propagate failures
394
394
395
-
```js
395
+
```js copy
396
396
+(async function executor() {
397
397
try {
398
398
await asyncFunc1();
@@ -423,15 +423,15 @@ async1()
423
423
- Asynchronous functions can be executed and promises can be captured in an array
424
424
- Array method `reduce` can be used to make the sequential execution on promise settlement
0 commit comments