
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
var asyngleton = require('../'),
fs = require('fs');
//called ONCE
var readDir = asyngleton(function(callback) {
fs.readdir(__dirname, callback);
})
//initializes the singleton method above
readDir(function(err, files) {
//do stuff
})
//called after there's a result
readDir(function(err, files) {
//do stuff
});
Creates a new asyngleton function.
factory
- the factory method for creating the singleton. This is called ONCE.Resets the target asyngleton so the factory can be called again.
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...
});
creates a dictionary of singletons
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
});
name
- the name of the singleton in the dictionaryfactory
- the factory method incase the singleton doesn't exist
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) {
});
FAQs
asynchronously generate singletons
The npm package asyngleton receives a total of 6 weekly downloads. As such, asyngleton popularity was classified as not popular.
We found that asyngleton demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.