If I start a node REPL and call a function that returns a promise, the function (obviously) returns immediately and some information about the promise is displayed in the console:
$> node
> var foo = () => new Promise((resolve, reject) => setTimeout(resolve('yay'), 1000));
undefined
> foo().then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
Is there any way I can get node to wait, synchronously, for the promise to resolve (or reject) so that I can get the result printed to the console?
I've seen questions like this one but the solutions there all suggest tacking on a .then()
call to do what I want with the result (e.g. log it). However, that doesn't seem to work - note that I already have that in my example, but I never get any log output, so I need some other mechanism to keep the process spinning for long enough that I get to see the output (the string 'yay'
in the example).