dedupe-promise
v0.0.1
Published
Very simple key-based Promise deduplication cache. If there's no entry for the key, it runs the provided function and keeps it's returned Promise in the cache until it's resolved.
Downloads
4
Readme
dedupe-promise
Very simple key-based Promise deduplication cache. If there's no entry for the key, it runs the provided function and keeps it's returned Promise in the cache until it's resolved.
Example
A runnable version of this example can be found in example.js
in the repository.
import deduper from "dedupe-promise";
const cache = deduper();
cache.run("test1", () => {
console.log("running function test1");
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 2000);
})
});
cache.run("test1", () => {
console.log("running function test1");
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 2000);
})
});
// will only run test1 once
License, donations
GPL-3.0. If you want to support my work, you can:
Changelog
v0.0.1 (February 12th, 2024)
- Adaptation from syncpipe package