Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promise.inspect() #256

Closed
domenic opened this issue Apr 5, 2013 · 3 comments
Closed

promise.inspect() #256

domenic opened this issue Apr 5, 2013 · 3 comments

Comments

@domenic
Copy link
Collaborator

domenic commented Apr 5, 2013

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 Q.allSettled #257).
@kriskowal
Copy link
Owner

It’s a good argument.

@domenic domenic mentioned this issue Apr 5, 2013
@domenic
Copy link
Collaborator Author

domenic commented Apr 5, 2013

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
Copy link
Collaborator Author

domenic commented Apr 5, 2013

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 added a commit that referenced this issue May 5, 2013
`valueOf` is left deprecated.
@domenic domenic closed this as completed in 0ecdaed Jun 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants