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
docs: correctly reflect serial execution order instead of limited parallel. (#7335)
Update asynchronous-flow-control.md
-Fix: Corrected description to reflect serial execution order instead of limited parallel. Rearranged order to logically sequence "limited in series" after "in series" for better clarity.
Signed-off-by: MichaelAblerCode <[email protected]>
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/asynchronous-work/asynchronous-flow-control.md
+42-42
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,48 @@ function serialProcedure(operation) {
173
173
serialProcedure(operations.shift());
174
174
```
175
175
176
-
2.**Full parallel:** when ordering is not an issue, such as emailing a list of 1,000,000 email recipients.
176
+
2.**Limited in series:** functions will be executed in a strict sequential order, but with a limit on the number of executions. Useful when you need to process a large list but with a cap on the number of items successfully processed.
177
+
178
+
```js
179
+
let successCount =0;
180
+
181
+
functionfinal() {
182
+
console.log(`dispatched ${successCount} emails`);
183
+
console.log('finished');
184
+
}
185
+
186
+
functiondispatch(recipient, callback) {
187
+
// `sendEmail` is a hypothetical SMTP client
188
+
sendMail(
189
+
{
190
+
subject:'Dinner tonight',
191
+
message:'We have lots of cabbage on the plate. You coming?',
if (!recipient || successCount >=1000000) returnfinal();
258
-
dispatch(recipient, function (_err) {
259
-
if (!_err) successCount +=1;
260
-
serial(bigList.pop());
261
-
});
262
-
}
263
-
264
-
serial(bigList.pop());
265
-
});
266
-
}
267
-
268
-
sendOneMillionEmailsOnly();
269
-
```
270
-
271
271
Each has its own use cases, benefits, and issues you can experiment and read about in more detail. Most importantly, remember to modularize your operations and use callbacks! If you feel any doubt, treat everything as if it were middleware!
0 commit comments