node-switchback
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -32,2 +32,9 @@ /** | ||
// Track whether a single tick of the event loop has elapsed yet since | ||
// this switchback was instantiated. | ||
var atLeastOneTickHasElapsed; | ||
setTimeout(function (){ | ||
atLeastOneTickHasElapsed = true; | ||
}, 0); | ||
// Build switchback | ||
@@ -43,3 +50,16 @@ var Switchback = factory(callbackContext); | ||
Switchback.emit = function() { | ||
return e.emit.apply(e, Array.prototype.slice.call(arguments)); | ||
var args = Array.prototype.slice.call(arguments); | ||
// This will invoke the final runtime function | ||
// | ||
// But first ensure at least a single cycle of the event loop has elapsed | ||
// since this switchback was instantiated | ||
if (atLeastOneTickHasElapsed) { | ||
return e.emit.apply(e, args); | ||
} | ||
else { | ||
setTimeout(function (){ | ||
return e.emit.apply(e, args); | ||
}, 0); | ||
} | ||
}; | ||
@@ -118,3 +138,15 @@ Switchback.on = function(evName, handler) { | ||
// Invoke final runtime function | ||
runtimeHandler.apply(runtimeCtx, runtimeArgs); | ||
// | ||
// But first ensure at least a single cycle of the event loop has elapsed | ||
// since this switchback was instantiated | ||
if (atLeastOneTickHasElapsed) { | ||
runtimeHandler.apply(runtimeCtx, runtimeArgs); | ||
} | ||
// Otherwise wait until that happens and then invoke the runtime function | ||
else { | ||
setTimeout(function (){ | ||
runtimeHandler.apply(runtimeCtx, runtimeArgs); | ||
}, 0); | ||
} | ||
}; | ||
@@ -121,0 +153,0 @@ }); |
{ | ||
"name": "node-switchback", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Normalize callback fns to switchbacks and vice versa", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25329
14
432