File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1191,6 +1191,30 @@ active handle in the event system. If the worker is already `unref()`ed calling
11911191
11921192## Notes
11931193
1194+ ### Synchronous blocking of stdio
1195+
1196+ ` Worker ` s utilize message passing via {MessagePort} to implement interactions
1197+ with ` stdio ` . This means that ` stdio ` output originating from a ` Worker ` can
1198+ get blocked by synchronous code on the receiving end that is blocking the
1199+ Node.js event loop.
1200+
1201+ ``` js
1202+ ' use strict' ;
1203+
1204+ const {
1205+ Worker ,
1206+ isMainThread ,
1207+ } = require (' worker_threads' );
1208+
1209+ if (isMainThread) {
1210+ new Worker (__filename );
1211+ for (let n = 0 ; n < 1e10 ; n++ ) {}
1212+ } else {
1213+ // This output will be blocked by the for loop in the main thread
1214+ console .log (' foo' );
1215+ }
1216+ ```
1217+
11941218### Launching worker threads from preload scripts
11951219
11961220Take care when launching worker threads from preload scripts (scripts loaded
You can’t perform that action at this time.
0 commit comments