Kludge
Kludge

Reputation: 2835

Getting data from fulfilled Q promise object in node REPL

Consider this simple Q promise object:

nesh> var p = functionThatReturnsPromise();

The REPL is kind enough to output the promise's state and value if I go:

nesh> p
{ state: 'fulfilled',
  value: 
   {
     // (data properties)
   }
}

Suppose I indeed waited for the promise to fulfill, I can't get the value nor the state directly by p.value or p.state.

I can do something like:

nesh> var data
undefined
nesh> p.then(function(_data) { data = _data })

yet it feels clumsy and uncomfortable for fluent REPL workflow.

Any ideas?

Upvotes: 2

Views: 1460

Answers (2)

shaunc
shaunc

Reputation: 5611

You can try this:

p.then(function (value) { debugger; });

Then "continue" -- execution will stop when promise is fulfilled and callback is called. Note however, it seems to freeze, node 0.12.4, though I'd think this was a node bug -- perhaps will work for you.

Upvotes: 0

nitishagar
nitishagar

Reputation: 9413

var p = functionThatReturnsPromise();

Promises do have the state and value defined, but for accessing that you need to use the valueOf() function over this.

p.valueOf() ==> promise value
p.inspect() ==> { state: 'fulfilled', value: 'data' }

Upvotes: 3

Related Questions