> await new Promise(() => {}); // or any "thenable"
// hangs
proposed solution is to add a timeout
Do you have any suggestion for the expected behavior?
oops i forgot to say in the comment, i think a timeout should be added so things that won't resolve don't hang the repl
FWIW, Chrome console returns immediately in this case.
Chrome console doesn't "return" immediately, in that a returned value isn't shown. It just opens up the console to let one execute more code. This reflects on a fundamental difference between the Chrome console and Node.js REPL: while the Chrome console is asynchronous, the Node.js REPL is synchronous (not in its internals but in its operation).
I'm not sure if a timeout would be what users expect, especially since one can stop waiting for the promise by Ctrl+C. The REPL will return to the "Read" stage and the user can evaluate more expressions, but note, unlike synchronous methods Ctrl+C'ing does not halt the promise's execution.
Maybe not pause the prompt and log out the result when it is resolved/avalible.
i'm working on a system where awaits that run longer than a tick get an "await id" and then when they resolve will be output with that id
```js
await Promise.resolve(5);
5
await new Promise(r => setTimeout(() => r('done'), 1000));
AWAIT01 (pending)
5 + 5
10
AWAIT01 => 'done'
Using require('repl') for the actual custom repl implementation will hard hang node on un-fulfilling promise, (NO reaction to SIGINT, only SIGTERM kills it).
@pkit You can specify the breakEvalOnSigint option of repl.start to allow SIGINT detection.
@TimothyGu I already have it set, top level await will hang anyway
Most helpful comment
Chrome console doesn't "return" immediately, in that a returned value isn't shown. It just opens up the console to let one execute more code. This reflects on a fundamental difference between the Chrome console and Node.js REPL: while the Chrome console is asynchronous, the Node.js REPL is synchronous (not in its internals but in its operation).
I'm not sure if a timeout would be what users expect, especially since one can stop waiting for the promise by Ctrl+C. The REPL will return to the "Read" stage and the user can evaluate more expressions, but note, unlike synchronous methods Ctrl+C'ing does not halt the promise's execution.