Skip to content

EdwardZZZ/async-run-once

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published