Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

promise.inspect() #256

Closed
domenic opened this Issue · 3 comments

2 participants

@domenic
Collaborator

I think the synchronous inspection API we have currently is clunky. My ideal one would look like promise.inspect() (or inspectState, or snapshot, or stateSnapshot, ...), which returns a "snapshot" object that is one of:

  • { state = "pending" }
  • { state = "fulfilled", value }
  • { state = "rejected", reason }

The advantage of this over promise.state, promise.value, and promise.reason are:

  • In ES3, properties on the promise have to be mutable, which is confusing.
  • Even in ES5, if we were to make those getters, I think it's less-clear that they are a read-only API than a snapshot-returning function.
  • Reduced surface area.
  • Usefulness for Q.allSettled (see #257).
@kriskowal
Owner

It’s a good argument.

@domenic domenic referenced this issue
Closed

Q.allSettled #257

@domenic
Collaborator

Optionally, { state = "pending", resolution = promiseWeAreWaitingOn }?

Also, we'd of course keep the rather-convenient Q.isFulfilled, Q.isRejected, Q.isPending, and their promise-prototype counterparts. We could additionally add Q.isSettled and Q.nearest (nearer? both?). If we added the resolution idea then Q.nearest could be easily implemented in terms of that, which is kind of nice, I think.

@domenic
Collaborator

Ah, and I forgot to mention: Node.js's util.inspect treats inspect methods specially, by using their output instead of the usual enumerable-keys-and-their-values display. I think this is actually a plus, but, it's something to be aware of.

@domenic domenic referenced this issue from a commit
@domenic domenic Replace `valueOf` by `inspect`. Closes #256.
`valueOf` is left deprecated.
416a703
@domenic domenic closed this issue from a commit
@domenic domenic Replace `valueOf` by `inspect`. Closes #256.
`valueOf` is left deprecated.
0ecdaed
@domenic domenic closed this in 0ecdaed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.