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

asyngleton

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyngleton - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

56

lib/index.js
var EventEmitter = require("events").EventEmitter;
var singletonIndex = 0;
/**

@@ -8,6 +10,9 @@ */

var em = new EventEmitter(), singletonArgs, loading, ret;
var _id = singletonIndex++;
var asyngleton = function() {
var asyng = asyngleton.info.call(this);
var args, cb, callback = arguments[arguments.length - 1];

@@ -20,23 +25,21 @@

//result already set? return the value
if(singletonArgs) {
callback.apply(this, singletonArgs);
//return the value if there is one
return ret;
if(asyng.result) {
callback.apply(this, asyng.result);
return this;
}
em.once("singleton", callback);
asyng.em.once("singleton", callback);
//still loading? add listener to event emitter
if(loading) {
return;
if(asyng.loading) {
return this;
}
loading = true;
asyng.loading = true;
args = Array.prototype.slice.call(arguments, 0);
cb = function() {
singletonArgs = Array.prototype.slice.call(arguments, 0);
em.emit.apply(em, ["singleton"].concat(singletonArgs));
asyng.result = Array.prototype.slice.call(arguments, 0);
asyng.em.emit.apply(asyng.em, ["singleton"].concat(asyng.result));
};

@@ -60,12 +63,33 @@

loading = false;
ret = undefined;
singletonArgs = undefined;
var asyng = asyngleton.info.call(this);
asyng.loading = false;
asyng.result = undefined;
return asyngleton;
};
asyngleton.info = function() {
if(!this._asyngleton) {
this._asyngleton = {
};
}
var asyng;
if(!(asyng = this._asyngleton[_id])) {
asyng = this._asyngleton[_id] = {
result: null,
loading: false,
em: new EventEmitter()
}
}
return asyng;
}
return asyngleton;
}
/**

@@ -72,0 +96,0 @@ */

@@ -5,3 +5,3 @@ {

"description": "asynchronously generate singletons",
"version": "0.1.0",
"version": "0.1.1",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

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