process.nextTick क्या है
process.nextTick current operation के ठीक बाद, किसी भी दूसरे async work से पहले, एक callback चलने के लिए schedule करता है।
In this page:
Syntax
process.nextTick(() => {
// runs before promise callbacks and the next event loop phase
});
process.nextTick
nextTick callbacks promise microtasks से पहले और event loop आगे बढ़ने से पहले process होते हैं। यह इन्हें यह सुनिश्चित करने के लिए useful बनाता है कि एक emitter के listeners इसके fire होने से पहले exist करें, लेकिन overuse I/O starve कर सकता है। setImmediate I/O के बाद check phase में चलता है।
Note:
nextTick की ordering न चाहिए तो नए code में queueMicrotask या setImmediate prefer करें।
उदाहरण: process.nextTick
setImmediate(() => console.log("setImmediate"));
Promise.resolve().then(() => console.log("promise then"));
process.nextTick(() => console.log("nextTick"));
console.log("sync");
// Output:
// sync
// nextTick
// promise then
// setImmediate
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- nextTick को recursively call करना और I/O starve करना
- nextTick को setImmediate से confuse करना
- यह उम्मीद करना कि nextTick promises के बाद चलेगा
चैप्टर सारांश
- nextTick promises से पहले चलता है
- यह loop जारी रहने से पहले चलता है
- Overuse I/O starve करता है
- setImmediate I/O के बाद चलता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: