Skip to content

Commit 1fe4f1d

Browse files
committed
make the node stdout flush workaround optional; fixes #2734
1 parent e4cbc91 commit 1fe4f1d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/postamble.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function exit(status) {
174174
// exit the runtime
175175
exitRuntime();
176176

177+
#if NODE_STDOUT_FLUSH_WORKAROUND
177178
if (ENVIRONMENT_IS_NODE) {
178179
// Work around a node.js bug where stdout buffer is not flushed at process exit:
179180
// Instead of process.exit() directly, wait for stdout flush event.
@@ -188,7 +189,9 @@ function exit(status) {
188189
setTimeout(function() {
189190
process['exit'](status);
190191
}, 500);
191-
} else if (ENVIRONMENT_IS_SHELL && typeof quit === 'function') {
192+
} else
193+
#endif
194+
if (ENVIRONMENT_IS_SHELL && typeof quit === 'function') {
192195
quit(status);
193196
}
194197
// if we reach here, we must throw an exception to halt the current execution

src/settings.js

+3
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ var NAMED_GLOBALS = 0; // If 1, we use global variables for globals. Otherwise
363363
// they are referred to by a base plus an offset (called an indexed global),
364364
// saving global variables but adding runtime overhead.
365365

366+
var NODE_STDOUT_FLUSH_WORKAROUND = 1; // Whether or not to work around node issues with not flushing stdout. This
367+
// can cause unnecessary whitespace to be printed.
368+
366369
var EXPORTED_FUNCTIONS = ['_main', '_malloc'];
367370
// Functions that are explicitly exported. These functions are kept alive
368371
// through LLVM dead code elimination, and also made accessible outside of

0 commit comments

Comments
 (0)