async-run-once
v1.1.2
Published
让异步代码只运行一次 make async function run only one time.
Downloads
4
Readme
async-run-once
让异步代码只运行一次 make async function run only one time.
install
$ npm i -S async-run-once
usage
// once(fn)(...args);
// once(fn(...args));
const once = require('async-run-once');
const getName = () => new Promise((resolve) => {
console.log(111);
setTimeout(() => {
resolve('hehe');
}, 1000);
});
const newGetName = once(getName);
[...Array(10)].forEach(async () => {
const name = await newGetName();
// const name = await getName();
console.log(name);
});
setTimeout(async () => {
console.log('-----')
const name = await newGetName();
console.log('>>', name);
}, 3000)