pausable

4.4.2 • Public • Published

Pausable

Build Status

Pause and resume JavaScript code from arbitrary points.

Installation

$ npm install pausable

Usage

let pausable = require('pausable');

Execute code where the top level can pause

(async () => {
    let myResult = await pausable.execute(`
// Pause at this point for 4 seconds, after which
// myVar should be assigned the value "my string"
var myVar = giveMeAfter('my string', 4000);
 
return myVar + ' with something appended';
`, {
    expose: {
        giveMeAfter(value, milliseconds) {
            var pause = pausable.createPause();
 
            setTimeout(() => {
                // Timeout has elapsed, so we can resume the paused code
                pause.resume(value);
            }, milliseconds);
 
            // Do the pause
            pause.now();
        }
    }
});
 
    console.log(myResult);
})();

Output:

my string with something appended

Readme

Keywords

Package Sidebar

Install

npm i pausable

Weekly Downloads

4

Version

4.4.2

License

MIT

Unpacked Size

438 kB

Total Files

93

Last publish

Collaborators

  • asmblah