queueMicrotask()
serves a similar purpose to process.nextTick()
with the additional advantage that queueMicrotask()
is specified in the WHATWG HTML Living Standard and supported on both modern browsers and Node.js (v11.0.0 and later).
When to use queueMicrotask()
vs. process.nextTick()
in the Node.js API documentation states:
For most userland use cases, the
queueMicrotask()
API provides a portable and reliable mechanism for deferring execution that works across multiple JavaScript platform environments and should be favored overprocess.nextTick()
. In simple scenarios,queueMicrotask()
can be a drop-in replacement forprocess.nextTick()
.
I propose adding a rule to warn when process.nextTick
is used, and suggest queueMicrotask()
as an alternative.
process.nextTick(() => process.exit(0));
process.nextTick(process.exit);
process.nextTick(process.exit, 1);
const fun = process.nextTick;
fun(process.nextTick);
queueMicrotask(() => process.exit(0));
queueMicrotask(process.exit);
// Note: queueMicrotask takes exactly 1 arg.
// Fail example fixed using .bind().
queueMicrotask(process.exit.bind(undefined, 1));
// Not sure if this should be auto-fixed.
// fun may be called with multiple args.
const fun = queueMicrotask;
// Not sure if this should be auto-fixed.
// fun may call its argument with multiple args.
fun(process.nextTick);
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too