This is a tiny library to create and manage singleton instances.
Table of Contents
npm install singa --save
The singa function returns an object of type Singa, with all input parameters, including name and factory, being entirely optional.
Sync
import { singa } from 'singa';
class Foo {
}
const singleton = singa({
name: 'singleton',
factory() {
return new Foo();
},
});
const instance = singleton.use();
Async
import { singaAsync } from 'singa';
class Foo {
}
const singleton = singaAsync({
name: 'singleton',
async factory() {
await Promise.resolve();
return new Foo();
},
});
const instance = await singleton.use();
Before starting to work on a pull request, it is important to review the guidelines for contributing and the code of conduct. These guidelines will help to ensure that contributions are made effectively and are accepted.
Made with 💚
Published under MIT License.