GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Why don't we use promises in our API? · Issue #551 · googleapis/google-cloud-node

Why don't we use promises in our API? #551

New issue
Copy link
New issue
Copy link
Closed
Closed
Why don't we use promises in our API?#551
Copy link
Assignees
callmehiphop
Labels
type: questionRequest for information or clarification. Not an issue.

Description

@jgeewax
jgeewax
opened on May 8, 2015
Issue body actions

UPDATE (4/25/16)

Promises coming soon. Track progress here: #1142


Seems like we're passing callbacks in rather than getting promises back -- was this an explicit choice?

/cc @idosela

Reacted by Chris Hiestand, Huanᶜ, Mark Herhold, Jason Dobry, Tobias Cudnik and Hunter Beast

Activity

Next
  1. jgeewax
    added
    type: questionRequest for information or clarification. Not an issue.
    on May 8, 2015
  2. jgeewax
    added this to the Core Future milestone on May 8, 2015
  3. stephenplusplus commented on May 8, 2015

    @stephenplusplus
    stephenplusplus
    on May 8, 2015
    Contributor
    More actions

    Why should we use promises? We talked about it before, but Node is callbacks, promises are an abstraction layer that not everybody enjoys using.

  4. jgeewax commented on May 8, 2015

    @jgeewax
    jgeewax
    on May 8, 2015
    ContributorAuthor
    More actions

    I'll leave it to @idosela to chime in on why he thinks they're great :)

    I actually think they're nice, but don't think it's a make-or-break.

  5. ryanseys commented on May 8, 2015

    @ryanseys
    ryanseys
    on May 8, 2015
    Contributor
    More actions

    Yeah I think it'd be way too much work now (for us and for our users) to switch. That's a design decision definitely made up front. Also, all our dependencies and the large majority of npm packages in general use callbacks, so while I can understand the appeal for Promises for certain cases, they don't exactly sit well with what people come to expect from a Node library.

  6. jgeewax commented on May 8, 2015

    @jgeewax
    jgeewax
    on May 8, 2015
    ContributorAuthor
    More actions

    And I'm guessing that if someone wanted to, they could wrap what we have and add promises... I'm going to close this out as I think we've answered the question:

    • Yes, we talked about it before, but it wasn't a consistent with the rest of the Node libraries out there.
    • Yes, it's nice, but we probably won't add it.
    • If someone really loves promises, they're welcome to fork and maintain their own wrapper?

    Feel free to re-open @idosela if you think we're making a huge mistake, otherwise we'll continue with our trusty ol' callbacks :)

  7. jgeewax
    closed this as completedon May 8, 2015
  8. jgeewax
    added
    status: won't fix
    on May 8, 2015
  9. jgeewax commented on May 8, 2015

    @jgeewax
    jgeewax
    on May 8, 2015
    ContributorAuthor
    More actions

    ... and @silvolu just pointed me at https://www.npmjs.com/package/gcloud-promise (hosted at https://github.com/sramam/gcloud-promise)

    Thanks @sramam ! 👍

  10. idosela commented on May 10, 2015

    @idosela
    idosela
    on May 10, 2015
    More actions

    TL;DR; I like promises, but I understand it would take a lot of work to switch to promises, so feel free to leave the issue closed.

    I find promises to be very convenient for handling async operations. The most common use cases in which promises provide significant advantage over callbacks are combination, chaining, and error handling.

    Let's say I want to fire off 10 Datastore queries, and then do something when they are all done.
    With callbacks I would have to write a bunch of code to track when each query is complete. With promises I can combine all of the promises returned by each individual query into a single promise which will be resolved when all of the queries are done. All it takes is a single function call.

    Promise chaining allows you to break down sequential async operations which depend on each other's return values, without having to resort to nesting of callbacks. This leads to a more readable and testable code.

    Promises also allow the user of your API to write less code, and have more flexibility. For example, with callbacks I constantly have to check whether an error happened, and can't have a single error handler for multiple related operations.

    Callbacks

    dataset.save({key: blogPostKey, data: blogPostData}, function(err, response) {
      // Handle error in step 1.
      if (err) {
        return;
      }
    
      dataset.save({key: blogPostKey, data: {isDraft: false}}, function(err, response) {
        // Handle error in step 1.
        if (err) {
          return;
        }
    
        // Do something on success.
      });  
    });

    Promises

    dataset.save({key: blogPostKey, data: blogPostData})
        .then(function(response) {
          return dataset.save({key: blogPostKey, data: {isDraft: false}});
        })
        .then(function(response) {
          // Do something on success.
        })
        .catch(function(err) {
          // Handle errors from step 1 or 2.
        });

    Q (https://github.com/kriskowal/q) provides much more detailed comparison of callbacks and promises, and I know of several Node packages that use it. I'm no Node expert, but it seems to me Promises are a pattern that is not language or environment specific.

    Sorry for going on and on :) Have a great weekend!

  11. jgeewax commented on May 10, 2015

    @jgeewax
    jgeewax
    on May 10, 2015
    ContributorAuthor
    More actions

    Out of curiosity -- is there a way we could easily support both ?

  12. jgeewax commented on Jun 6, 2015

    @jgeewax
    jgeewax
    on Jun 6, 2015
    ContributorAuthor
    More actions

    I'm reopening this issue mainly because ... I've been writing more stuff in Node and promises are becoming nicer and nicer.

    Some libraries that use promises that seem really nice:

    • http://docs.sequelizejs.com/en/latest/
    • https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-logging-users-in

    I think our library would be... kind of amazing if we could offer promises as well as the callback style we have today.

    If we were to invest in this, I'd love if it we could do the work to support promises, without documenting them, and once they are ubiquitous in the library, we post the documentation.

    Thoughts?

    Reacted by Huanᶜ and Hoovinator
  13. jgeewax
    reopened this on Jun 6, 2015
  14. ryanseys commented on Jun 8, 2015

    @ryanseys
    ryanseys
    on Jun 8, 2015
    Contributor
    More actions

    What value does it add? What do you mean by "nicer and nicer"? Callbacks vs. Promises is mainly, I feel, just a personal preference. I don't like the idea of mixing both callbacks and promises because it can confuse people if they mix them. Do you know of any popular node libraries that support both callbacks and promises out of the box?

    Reacted by Hoovinator
  15. jgeewax commented on Jun 8, 2015

    @jgeewax
    jgeewax
    on Jun 8, 2015
    ContributorAuthor
    More actions

    What value does it add? What do you mean by "nicer and nicer"? Callbacks vs. Promises is mainly, I feel, just a personal preference.

    I'd consider the nesting of callbacks to be an anti-pattern... Further, "we accept a callback" is rather restrictive -- and "we return a promise, do what you want" is much more open.

    I don't like the idea of mixing both callbacks and promises because it can confuse people if they mix them.

    This could be true, but what's wrong with saying in the docs: "this method accepts a callback, and returns a promise" ? Does that really confuse you?

    Do you know of any popular node libraries that support both callbacks and promises out of the box?

    @idosela : Do you know of any popular node libraries that support both? I don't know of any off the top of my head...

    Reacted by buildbreakdo
  16. 96 remaining items

  17. sofisl
    added a commit that references this issue on Jan 28, 2026

    chore: [CHANGE ME] Re-generated to pick up changes in the API or clie…

    276d8ba
  18. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    fix: update datastore_transactional_single_entity_group_read_only to …

    f9af874
  19. GautamSharda
    added a commit that references this issue on Feb 2, 2026

    chore: release 4.0.2 (#551)

    af8af3e
  20. sofisl
    added a commit that references this issue on Feb 3, 2026

    feat: add typescript support for script statistics (#551)

    afada78
  21. GautamSharda
    added a commit that references this issue on Feb 3, 2026

    chore: release 4.0.2 (#551)

    b390957
  22. sofisl
    added 2 commits that reference this issue on Feb 4, 2026

    build: auto-approve renovate-bot PRs for minor updates (#1145) (#551)

    67705dd

    fix: update datastore_transactional_single_entity_group_read_only to …

    b844f19
  23. sofisl
    added 3 commits that reference this issue on Feb 24, 2026

    chore(deps): update dependency mocha to v6

    93c60b9

    fix(build): fix Kokoro release script (#551)

    3944326

    build: use node10 to run samples-test, system-test etc (#551)

    b948e8e
  24. GautamSharda
    added 3 commits that reference this issue on Mar 5, 2026

    chore: update deps (#551)

    bbeae8b

    build: use per-repo npm publish token (#551)

    b2cb992

    docs: document version support goals (#551)

    040b6db
  25. sofisl
    added a commit that references this issue on Mar 17, 2026

    chore(main): release 7.2.0 (#551)

    b2bd700
  26. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    fix(build): fix Kokoro release script (googleapis#551)

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

Metadata

Metadata

Assignees

  • @callmehiphop
    callmehiphop

Labels

type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.