Node.js tick callback , , process.nextTick, , , , , .
:
// this will print "hi!", followed by "hello there"
process.nextTick(function() {
console.log('hello there');
});
console.log('hi!');
:
// this will just print "hi!", and an error will be thrown later on
process.nextTick(undefined);
console.log('hi!');
, .
1: longjohn
, , .
longjohn ( npm), require - . , :
TypeError: Cannot read property 'apply' of undefined
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
at Function.Module.runMain (module.js:443:11)
at startup (node.js:139:18)
at node.js:968:3
---------------------------------------------
at Object.<anonymous> (.../example.js:3:9)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
, , , , process.nextTick undefined, .
javascript , process.nextTick ( ), , - nextTick:
var nextTick = process.nextTick;
process.nextTick = function(callback) {
if (typeof callback !== 'function') {
console.trace(typeof callback + ' is not a function');
}
return nextTick.apply(process, arguments);
};
. , , - process.nextTick. , process, - , , , , . (: , , .)
Trace: undefined is not a function
at process.nextTick (.../example.js:5:13)
at Object.<anonymous> (.../example.js:10:9)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
, , , .
_tickCallback node.js ( ).