What is a blocking function or a blocking call?
This is a term I see again and again when referring to Node.js or realtime processing languages.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A function that stops script execution until it ends.
For example, if I had a function in my language that was used to write to a file, like so:
The
printstatement would only be executed once the file has been written to the disk. The whole program is halted on this instruction. This isn’t noticeable for small enough writes, but imagine I had a huge blob to write to the file, one that took many seconds:The
printstatement would only be executed after a few seconds of writting, and the whole program would be stopped for that time. In Node.js, this stuff is done asynchronously, using events and callbacks. Our example would become:Where the third parameter is a function to be called once the file has been written. The
printstatement located after the write function would be called immediately after, whether or not the file has been written yet. So if we were to write a huge enough blob, the output might look like this:This makes applictions very fast because you’re not waiting on a client message, a file write or other. You can keep on processing the data in a parallel manner. This is considered by many one of the strengths of Node.js.