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.0.2 to 0.1.0

.cupboard

16

lib/index.js

@@ -15,3 +15,3 @@ var EventEmitter = require("events").EventEmitter;

if(!(typeof callback == "function")) {
callback = function(){};
callback = function(){ };
}

@@ -21,3 +21,3 @@

if(singletonArgs) {
callback.apply(null, singletonArgs);
callback.apply(this, singletonArgs);

@@ -29,3 +29,3 @@ //return the value if there is one

em.on("singleton", callback);
em.once("singleton", callback);

@@ -43,5 +43,2 @@ //still loading? add listener to event emitter

em.emit.apply(em, ["singleton"].concat(singletonArgs));
//dispose
em.removeAllListeners("singleton");
};

@@ -57,8 +54,5 @@

//returned a value? Then it's not async...
if (ret = fn.apply(this, args)) {
cb(ret);
return ret;
}
fn.apply(this, args);
return this;
};

@@ -65,0 +59,0 @@

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

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

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

@@ -0,1 +1,2 @@

[![build status](https://secure.travis-ci.org/crcn/asyngleton.js.png)](http://travis-ci.org/crcn/asyngleton.js)
### Example

@@ -86,2 +87,34 @@

- `name` - the name of the singleton in the dictionary
- `factory` - the factory method incase the singleton doesn't exist
- `factory` - the factory method incase the singleton doesn't exist
### [Structr](/crcn/structr.js) Integration
```javascript
var structr = require("structr");
structr.mixin(require("asyngleton"));
var TestClass = structr({
/**
*/
"singleton load": function(onLoad) {
fs.readFile(__dirname + "/config.json", onLoad);
}
});
var test = new TestClass();
test.load(function(config) {
});
//fs.readFile is NOT called again at this point
test.load(function(config) {
});
```
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