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

Is Q a superset of a native Promise? #843

Open
andykais opened this issue Apr 15, 2019 · 4 comments
Open

Is Q a superset of a native Promise? #843

andykais opened this issue Apr 15, 2019 · 4 comments

Comments

@andykais
Copy link

Hi, new to using Q here in an existing codebase. Could someone clarify this for me? A Q promise has all the functionality of a native promise, with no changed behavior, correct? There are only additional methods that allow more functionality?

#836 mentioned that you can coerce a promise from a Q promise with

Promise.resolve(Q.resolve(1))

but I want to know if a Q promise can simply be used in-place of a native promise.

@andykais
Copy link
Author

follow up question, what is the interopability between native promises and Q promises? Are these both legal

const nativePromise = (n) => new Promise(resolve => setTimeout(resolve, n))
const qPromise = (n) => {
  const deferred = q.defer()
  setTimeout(() => deferred.resolve(), n)
  return deferred.promise
}

const qPromiseFromNative = Q.resolve(nativePromise(100))
const nativePromiseFromQ = Promise.resolve(qPromise(100))

@benjamingr
Copy link
Collaborator

No, but it is pretty close, for example native promises have more guarantees on timings

@andykais
Copy link
Author

Thanks, I was able to discover some differences with unhandledRejections as well. A native promise will become unhandled at the end of one node event loop. A Q promise does not have that guarantee. Q uses its own custom nextTick, so it makes sense.

If you wish to elaborate on their differences I would be interested. If not, feel free to close this issue. I see that there are subtle differences now.

@benjamingr
Copy link
Collaborator

@andykais well, I (helped) spec how unhandledRejection behaves in Node ( https://gist.github.com/benjamingr/0237932cee84712951a2 ) and I added the events to Q ( #643 ).

I don't think you should rely on the differences between Q and Node here :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants