Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skyrising/await-repl
Wrapper for Node.js' repl.start() faking await functionality
https://github.com/skyrising/await-repl
Last synced: about 2 months ago
JSON representation
Wrapper for Node.js' repl.start() faking await functionality
- Host: GitHub
- URL: https://github.com/skyrising/await-repl
- Owner: skyrising
- License: gpl-3.0
- Created: 2016-12-31T13:51:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-01T17:03:33.000Z (about 8 years ago)
- Last Synced: 2024-10-31T19:07:39.221Z (2 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# await-repl
## Wrapper for `repl.start()`await-repl is a simple wrapper for [repl.start()](https://nodejs.org/api/repl.html#repl_repl_start_options) 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
```javascript
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
```javascript
> await 42
42
> await Promise.resolve(73)
73
> await new Promise((resolve, reject) => setTimeout(() => resolve('foo'), 1000))
/* After 1 second */
'foo'
>
```#### Previous behavior
```javascript
> 42
42
> Promise.resolve(73)
Promise { 73 }
> new Promise((resolve, reject) => setTimeout(() => resolve('foo'), 1000))
Promise { }
>
```### Limitations
Works only for lines __starting__ with 'await ' so things like the following don´t work:
```javascript
> let a = await getSomeValueFromDatabase(...)
```