Skip to content

Wrapper for Node.js' repl.start() faking await functionality

License

Notifications You must be signed in to change notification settings

skyrising/await-repl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

await-repl

Wrapper for repl.start()

await-repl is a simple wrapper for repl.start() that handles lines starting with 'await ' differently: instead of outputting the Promise (or value) it only returns when the Promise is resolved or rejected

Example

const awaitRepl = require('await-repl');
awaitRepl({
  rejectionHandler: (err) => 'Promise rejection: ' + err,
  awaitTimeout: 2000
});

Options

await-repl passes options to repl.start()

Additional options

  • rejectionHandler
    function for formatting Promise-rejections
    it is passed a callback(err, res) for returning the formatted error to the repl
    returning a value is the same as calling callback(returnValue)
  • awaitTimeout
    number of milliseconds before giving up waiting for Promises to be resolved
    will act like a Promise-rejection with new awaitRepl.AwaitTimeout()

REPL

> await 42
42
> await Promise.resolve(73)
73
> await new Promise((resolve, reject) => setTimeout(() => resolve('foo'), 1000))
/* After 1 second */
'foo'
>

Previous behavior

> 42
42
> Promise.resolve(73)
Promise { 73 }
> new Promise((resolve, reject) => setTimeout(() => resolve('foo'), 1000))
Promise { <pending> }
>

Limitations

Works only for lines starting with 'await ' so things like the following don´t work:

> let a = await getSomeValueFromDatabase(...)

About

Wrapper for Node.js' repl.start() faking await functionality

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published