Package Exports
- pause-methods
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pause-methods) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pause-methods
A Node.js module to pause/resume execution of the object's methods
const {pause, resume} = require('pause-methods');
const obj = {
methodA() {
process.stdout.write('hello');
},
methodB() {
process.stdout.write('world');
}
};
const pausedObj = pause(obj);
pausedObj.methodA(); // prints nothing
pausedObj.methodB(); // prints nothing
resume(pausedObj); // prints 'hello' and 'world'
Installation
npm install pause-methods
API
const pauseMethods = require('pause-methods');
pauseMethods(obj)
obj: Object
Return: Object
(a reference to obj)
It makes obj's enumerable Function
properties do nothing and return undefined
.
let num = 0;
const obj = {countUp: () => ++num};
obj.countUp(); //=> 1
num; //=> 1
const pausedObj = pauseFn(obj);
pausedObj.countUp(); //=> undefined, not 2
num; //=> 1, not 2
pausedObj.countUp(); //=> undefined
pausedObj.countUp(); //=> undefined
pausedObj.countUp(); //=> undefined
// ...
num; //=> 1
pauseMethods.pause(obj)
An alias of pauseMethods()
.
pauseMethods.resume(obj)
obj: Object
returned by pauseMethods()
Return: Object
(a reference to obj)
It restores the original functionality of the paused methods, calls it with each arguments passed while paused.
const pausedFs = pauseMethods(fs.promises);
(async () => {
await pausedFs.writeFile('./a', 'foo'); // ./a is not created here
await pausedFs.mkdir('./b'); // ./b is not created here
pauseFs.resume(); // ./a and ./b are created here
})();
License
ISC License © 2019 Shinnosuke Watanabe