node.js - In NodeJS, will `fs.writeFile()` in event handler block the main thread at a certain time point? -


i know fs.writefile() asynchronous , delayed executed.

for example:

fs.writefile() console.log("non-blocking") // last statement of event handler function 

will print non-blocking , thread spend time execute operations write files.

however, if nodejs app single-threaded. when thread starts execute operations write files after executing console.log("non-blocking"). thread seems still being blocked, though blocking status delayed. blocking should happen before console.log("non-blocking") if fs.writefile replaced fs.writefilesync. when use fs.writefile here, blocking still seems exist when last statement of event handler finished , file writing operation started.

is true thread blocked when file-writing operations started? or blocking happen in main thread anyway. if so, there way avoid it?


i don't think question same how single threaded non blocking io model works in node.js, because question how nodejs interacts operation system file operations.

there's 1 thread... code. nodejs application contains/calls other threads doing operations (mainly io) , calling user thread on events.

when fs.writefile, action given native thread handles operation. if gave callback fs.writefile, user thread awoken execute it. core of asynchronous io operations management libuv.

here's document explaining model.

edit: voted close, there's more complete qa on topic.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -