Skip to content

Commit 3da59cc

Browse files
committed
fix(utils): ensureAsync: change from "setImmediate" to "process.nextTick"
1 parent 5605ea0 commit 3da59cc

File tree

1 file changed

+4
-4
lines changed
  • packages/mongodb-memory-server-core/src/util

1 file changed

+4
-4
lines changed

packages/mongodb-memory-server-core/src/util/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export async function killProcess(childprocess: ChildProcess, name: string): Pro
112112
*/
113113
export function isAlive(pid: number): boolean {
114114
try {
115-
process.kill(pid, 0);
115+
process.kill(pid, 0); // code "0" dosnt actually kill anything (on all supported systems)
116116

117117
return true;
118118
} catch (err) {
@@ -121,11 +121,11 @@ export function isAlive(pid: number): boolean {
121121
}
122122

123123
/**
124-
* Call "setImmediate" to ensure an function is exectued on next event loop
125-
* look at the following link to get to know on why this needed: https://snyk.io/blog/nodejs-how-even-quick-async-functions-can-block-the-event-loop-starve-io/
124+
* Call "process.nextTick" to ensure an function is exectued directly after all code surrounding it
125+
* look at the following link to get to know on why this needed: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick (read full documentation)
126126
*/
127127
export async function ensureAsync(): Promise<void> {
128-
return new Promise((res) => setImmediate(res));
128+
return new Promise((res) => process.nextTick(res));
129129
}
130130

131131
export function authDefault(opts: AutomaticAuth): Required<AutomaticAuth> {

0 commit comments

Comments
 (0)