Home > front end >  Process in nodejs. NextTick inside of the console log sequence
Process in nodejs. NextTick inside of the console log sequence

Time:01-24

 
const fs=require('fs');

Fs. ReadFile (__filename, ()=& gt; {
Process. NextTick ((e)=& gt; {
The console. The log (e)
The console. The error (e)
}, new TypeError (' argument should be the string '))
SetImmediate (()=& gt; {
The console. The log (' immediate ');
});
});


Output the following
TypeError: argument should be the string
At the D: \ projectOther \ mylib \ SRC \ test js: 7:5
The at FSReqCallback. ReadFileAfterClose [as the oncomplete] (internal/fs/read_file_context. Js: 63:3)
The immediate
TypeError: argument should be the string
At the D: \ projectOther \ mylib \ SRC \ test js: 7:5
The at FSReqCallback. ReadFileAfterClose [as the oncomplete] (internal/fs/read_file_context. Js: 63:3)


Why execution order is the console first. Log (e), then the console. The log (' immediate '), and finally the console. The error (e)
  • Related