New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.0 to 0.0.1

33

lib/index.js
var EventEmitter = require("events").EventEmitter;
module.exports = function(fn) {
/**
*/
function createAsyngleton(fn) {
var em = new EventEmitter(), singletonArgs, called;

@@ -43,5 +46,31 @@

called = false;
return ret;
}
return ret;
};
}
/**
*/
function createDictionary() {
var _dict = {};
return {
get: function(key, fn) {
if(_dict[key]) return _dict[key];
var asyngleton = _dict[key] = createAsyngleton(fn);
asyngleton.dispose = function() {
delete _dict[key];
}
return asyngleton;
}
}
}
module.exports = createAsyngleton;
module.exports.dictionary = createDictionary;

2

package.json

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

"description": "asynchronously generate singletons",
"version": "0.0.0",
"version": "0.0.1",
"repository": {

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

@@ -23,2 +23,65 @@ ### Example

```
```
### API
#### asyngleton(factory)
Creates a new asyngleton function.
- `factory` - the factory method for creating the singleton. This is called ONCE.
#### .reset()
Resets the target asyngleton so the factory can be called again.
```javascript
var fs = require('fs'),
asyngleton = require('asyngleton');
var readDir = asyngleton(function(callback) {
fs.readdir(__dirname, callback);
});
readDir(function(err, files) {
//make the readDir factory callable again
readDir.reset();
//do stuff...
});
```
#### .dictionary()
creates a dictionary of singletons
```javascript
var dict = require('asyngleton').dictionary(),
fs = require('fs');
var readThisDir = dict.get("readThisDir", function(onSingleton) {
fs.read(__dirname, onSingleton);
});
var readLibDir = dict.get("readLibDir", function(onSingleton) {
fs.read(__dirname + "/lib", onSingleton);
})
readThisDir(function(err, files) {
//do stuff
});
readLibDir(function(err, files) {
//do stuff
});
```
#### dictionary.get(name, factory)
- `name` - the name of the singleton in the dictionary
- `factory` - the factory method incase the singleton doesn't exist
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