Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-switchback

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-switchback - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

test/next-tick.test.js

36

lib/index.js

@@ -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 @@ });

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc