Summary of synchronous and asynchronous stepping on pits

These synchronous and asynchronous pits must be stepped on personally

I believe that everyone must have learned it, but they didn't notice it as soon as they did it.

So now I don’t expect everyone to remember, I just hope that one day I will meet it and be able to find it -=-

If you don't talk about the principle, proceed directly to the complete program.

My requirement: Encapsulate a function to create a folder
Function 1. Random folder name.
Function 2. You can control the amount of folder generation and the number of folder strings.

I encapsulated two functions, one passed in a parameter to generate a random string as the folder name, and the other function created the folder. The second function will call the first function. The second function encapsulates a loop, passing in two parameters, one to control the number of loops, and one to the randomly generated string function.

Does it feel simple...,,, yes, yes, it's so simple. But it pained me for a long time.

I am using nodejs this time. After this experience, I also understand why there are blind loops and chaotic loops in python before.

I have also learned about the main process, child process, synchronization, and asynchronous before. (If you are interested, please see the mutual call and mutual parameter transfer between bat, python, and nodejs that I wrote before )

Moreover, I believe that most of us feel that the asynchronous method is very good when we learn about synchronization and asynchrony. Asynchrony does not affect the main process, and even we don’t pay much attention to the synchronous method. When you need a synchronous method, you still think about where to write a callback function.

Paste the code

var fs=require(

Guess you like

Origin blog.csdn.net/Cml_l/article/details/114579993