An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
September 17, 2022 05:17 am GMT
Original Link: https://dev.to/ajaybaraiya6/loop-functions-in-synchronous-way-react-quick-notes-gbh
Loop functions in synchronous way React Quick Notes.
We all know term called Recursion. That is same we are doing in below example to loop through multiple functions which should execute one after another.
This is one of the ways we can achive function serialization and can be usfull to your application.
const objFunctions = [ { func: function1, args: args1 }, { func: function2, args: args2 }]; //We defined functions that we want to call one by one.function LoopFunctionOneByOneCallAfterOneAnother(objFunctions) { if (!objFunctions) process.exit(0); // finished ExecuteSingleFunctionCall(objFunctions, function (result) { // continue AFTER callback LoopFunctionOneByOneCallAfterOneAnother(objFunctions.shift()); });} // notice we called same function under this function which has parameter to get next object from objFunctions.function ExecuteSingleFunctionCall(objFunction, callback) { const { args, func } = objFunction; func(args, callback);} // Supportive function to execte single function. LoopFunctionOneByOneCallAfterOneAnother(objFunctions.shift()); // In the end we call our function.
So this whole block will execute in serialized manner.
Above referenced from site https://nodejs.dev/en/learn/asynchronous-flow-control/, you can find more usefull ways over here.
Original Link: https://dev.to/ajaybaraiya6/loop-functions-in-synchronous-way-react-quick-notes-gbh
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To