pause-fn
A Node.js module to pause/resume execution of a function
const pause resume = ;const pausedConsoleLog = ; ; //=> prints nothing; //=> prints nothing ; //=> prints '1\n' and '2 3\n'
Installation
npm install pause-fn
API
const pauseFn = ;
pauseFn(func)
func: Function
Return: Function
It returns a Function
that does nothing and always returns undefined
.
let num = 0;const countUp = ++num; ; //=> 1num; //=> 1 const pausedCountUp = ; ; //=> undefined, not 2num; //=> 1, not 2 ; //=> undefined; //=> undefined; //=> undefined// ...num; //=> 1
pauseFn.pause(func)
An alias of pauseFn()
.
pauseFn.resume(func)
func: Function
returned by pauseFn()
Return: any[]
It restores the original functionality of the paused Function
, calls it with the every arguments passed while paused, and returns the return values of each calls as an Array
.
const pausedMathMax = ; ; //=> undefined, not 0; //=> undefined, not Infinity // The original function works as usualMath; //=> 3 pauseFn; //=> [0, Infinity] // Unlike the variable name, it's no longer paused; //=> 3
License
ISC License © 2019 Shinnosuke Watanabe