funcrate
v0.1.0
Published
A library provides container for resolving async functions later
Downloads
5
Maintainers
Readme
Funcrate
A library provides container for resolving async functions later.
import { createCrate } from "funcrate";
const crate = createCrate();
// async function in crate can be invoked immediately
crate.add(1, 2).then(console.log); // → 3 (shown after crate registered)
// entity in crate can registered later
const asyncFunctions = {
async add(a, b) {
await new Promise(r => setTimeout(r, 100));
return a + b;
}
};
crate.register(asyncFunctions);
API
createCrate(): Crate
- @return: an empty
Crate
Creates a crate. While it already has async, those are not resolved until entity registered.
Crate.get(): T
- @return: proxy value that can be considered as registered value
Gets proxy value that can be considered as registered value.
Crate.register(value: T)
- @param
value
: entity in crate
Registers entity in crate. Entity must be an object that has only functions return any type Promise.