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 — compute onComplete example should show "the right way" to attach handlers? · Issue #921 · googleapis/google-cloud-node

compute onComplete example should show "the right way" to attach handlers? #921

New issue
Copy link
New issue
Copy link
Closed
Closed
compute onComplete example should show "the right way" to attach handlers?#921
Copy link
Assignees
callmehiphop
Labels
api: computeIssues related to the Compute Engine API.

Description

@jgeewax
jgeewax
opened on Oct 29, 2015
Issue body actions

On https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.24.1/compute/operation?method=onComplete

operation.onComplete(function(err, metadata) {
  if (err.code === 'OPERATION_INCOMPLETE') {
    // The operation is not complete yet. You may want to register another
    // `onComplete` listener or queue for later.
  }

  if (!err) {
    // Operation complete!
  }
});

This example doesn't really show me how I'm supposed to continue attaching handlers (and I would actually need to redesign the flow of my code to make this work).

Can we update the example to show exactly what "the right way" to do this is?

Activity

  1. stephenplusplus commented on Oct 29, 2015

    @stephenplusplus
    stephenplusplus
    on Oct 29, 2015
    Contributor
    More actions

    If we actually want to support "wait until it's done no matter what", we can maybe just say "pass maxAttempts: 0", which we can change our code to treat as "infinite"?

  2. stephenplusplus
    added
    api: computeIssues related to the Compute Engine API.
    on Oct 29, 2015
  3. jgeewax commented on Oct 29, 2015

    @jgeewax
    jgeewax
    on Oct 29, 2015
    ContributorAuthor
    More actions

    I think both are good things to do...

    It seems kind of weird that we have a handler called onComplete that can be called with an error of "OPERATION_INCOMPLETE"... Shouldn't we just not call the handler then ?

  4. stephenplusplus commented on Oct 29, 2015

    @stephenplusplus
    stephenplusplus
    on Oct 29, 2015
    Contributor
    More actions

    onComplete that can be called with an error of "OPERATION_INCOMPLETE"

    The error should really be considered as "OPERATION_DID_NOT_COMPLETE_WITHIN_ALLOWED_TIME".

    The concept of how the method works, re: attempts/being called with an error, is explained in the method description:

    If the operation doesn't complete after the maximum number of attempts have been made (see options.maxAttempts and options.interval), an error will be provided to your callback with code: OPERATION_INCOMPLETE.

    Shouldn't we just not call the handler then ?

    That makes sense, but I think we'd hear from developers saying "I need to know when all attempts are exhausted"-- it's just a way to give control/progress updates back to the user.

    Supporting "call only when it's complete" would be ideal, but since it can be error-prone to implement-- onComplete is just a convenience wrapper of setTimeout(getMetadata)-- we have to rely on the network and a proper API response to indicate it's complete. If those things don't happen exactly as we expect, the loop will go in indefinitely, without the user knowing that it's happening or being able to stop it or check on the status... which is why we have sane defaults and allow overrides (they could provide maxAttempts: 92834 if they really wanted)

    I think the easiest thing to do is what you originally wanted (:smile:); I'll just send a PR showing how to call onComplete again if you get the "DID_NOT_COMPLETE" error.

    // @callmehiphop if you have any thoughts on how this should work.

  5. jgeewax commented on Oct 29, 2015

    @jgeewax
    jgeewax
    on Oct 29, 2015
    ContributorAuthor
    More actions

    but I think we'd hear from developers saying "I need to know when all attempts are exhausted"

    Shouldn't that be .onTimeout() ?

  6. stephenplusplus commented on Oct 29, 2015

    @stephenplusplus
    stephenplusplus
    on Oct 29, 2015
    Contributor
    More actions

    That's interesting... we could turn it into a true event emitter:

    zone.createVM(function(err, vm, operation) {
      operation
        .on('complete', function(metadata) {})
        .on('error', function(err) {})
        .on('timeout', function() {
          if (something) {
            this.startPolling(); // start again
          }
        });
    
      operation.startPolling([options]);
    });
  7. jgeewax commented on Oct 29, 2015

    @jgeewax
    jgeewax
    on Oct 29, 2015 via email
    ContributorAuthor
    More actions
    +1 to that.
  8. callmehiphop commented on Oct 29, 2015

    @callmehiphop
    callmehiphop
    on Oct 29, 2015
    Contributor
    More actions

    I agree, a real event emitter would be much nicer imo

  9. stephenplusplus
    added
    enhancement
    on Oct 29, 2015
  10. callmehiphop
    closed this as completedin #939on Nov 17, 2015
  11. JustinBeckwith
    assigned
    callmehiphop
    on Feb 1, 2021
  12. miguelvelezsa
    added a commit that references this issue on Jul 23, 2025

    fix: properly bundle requests with snake_case (#921)

    45aac74
  13. sofisl
    added 6 commits that reference this issue on Jan 27, 2026

    chore(deps): update dependency tmp to v0.2.2 (#921)

    2a008db

    chore(deps): update dependency tmp to v0.2.2 (#921)

    ce02a8f

    chore(deps): update dependency tmp to v0.2.2 (#921)

    39165fb

    chore(deps): update dependency tmp to v0.2.2 (#921)

    950fe1c

    chore(deps): update dependency tmp to v0.2.2 (#921)

    b992af2

    chore(deps): update dependency tmp to v0.2.2 (#921)

    6274d32
  14. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    docs(samples): include metadata file, add exclusions for samples to h…

    471dd62
  15. sofisl
    added 3 commits that reference this issue on Jan 29, 2026

    chore(deps): update dependency tmp to v0.2.2 (#921)

    e94059a

    chore(deps): update dependency tmp to v0.2.2 (#921)

    f0ea335

    docs(samples): include metadata file, add exclusions for samples to h…

    ac4c5a3
  16. sofisl
    added a commit that references this issue on Feb 17, 2026

    docs(samples): include metadata file, add exclusions for samples to h…

    44abea8
  17. sofisl
    added 2 commits that reference this issue on Feb 25, 2026

    chore: release 4.1.1 (#921)

    45a8f45

    chore: update npm scripts and synth.py (#921)

    88951ab
  18. GautamSharda
    added a commit that references this issue on Mar 5, 2026

    docs: updated code of conduct (includes update to actions) (#921)

    03f8a8e
  19. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    chore: release 4.1.1 (googleapis#921)

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

Metadata

Metadata

Assignees

  • @callmehiphop
    callmehiphop

Labels

api: computeIssues related to the Compute Engine API.

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.