Skip to content

Check to determine if global.Promise is native promise #557

Closed

Description

@ORESoftware

On Node.js versions 4.0.0 <--> latest

Is there a way to check to determine if global.Promise is the native promise implementation? As opposed to Bluebird promises, etc?

Activity

  1. addaleax commented on Mar 29, 2017

    @addaleax
    Member

    The “official” way would be value instanceof Promise, the “correct” way that works across VM contexts would be process.binding('util').isPromise(value) (see nodejs/node-eps#44 for a proposal turning the latter into a public Node API).

  2. ORESoftware commented on Mar 29, 2017

    @ORESoftware
    Author

    hmmm
    sorry, I should been more detailed

    global.Promise  = require('bluebird')
    value instanceof Promise // will return true, but not indicate we are using native promises

    but the second methodology should work I think, right?

  3. addaleax commented on Mar 29, 2017

    @addaleax
    Member

    Ah, right, should have read that you were asking for checking global.Promise, not a promise.

    Yes, the second way should work.

  4. ORESoftware commented on Mar 29, 2017

    @ORESoftware
    Author

    process.binding('util') is the same as require('util') or no?

  5. addaleax commented on Mar 29, 2017

    @addaleax
    Member

    process.binding('util') is the same as require('util') or no?

    No, process.binding() gives you direct access to Node’s internal C++ APIs. It’s not part of our public API, so don’t rely on it being there forever. (Sorry – I fear that’s the best answer we have right now. If you want something more reliable, maybe engage in nodejs/node-eps#44 …)

  6. ORESoftware commented on Mar 29, 2017

    @ORESoftware
    Author

    sure will do thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions