0.0.1 • Published 9 months ago

run-once-js v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

run-once-js

Wraps a function that runs once. The call can continue after a delay of several milliseconds.

Install

npm install run-once-js

Or

yarn add run-once-js

Usage

parameter

parameterdesctypedefault
funcexecute functionFunction() => void 0
options.delayHow many milliseconds to delay before continuing executionnumber333
options.waitFunDoneWait for function execution to complete (asynchronous function)booleanfalse

example

import { runOnce } from 'run-once-js';

let i = 0;
const exec = (param1: any, param2: any) => {
  i++;
  window.console.log(param1, params2);
};

const run = runOnce({
  // The execution function must be passed
  func: exec,
  options: {
    // Execution can continue after 333 ms
    delay: 333,
    // Whether to wait for the async function
    waitFunDone: false
  }
});

// execute
run(2233, 3343);
// will not execute
run(2233);
// will not execute
run(2233);

Changelog

  • 0.0.1 basically available
0.0.1

9 months ago