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 — connection: use ~~process.nextTick~~ setImmediate by stephenplusplus · Pull Request #166 · googleapis/google-cloud-node

Conversation

@stephenplusplus

@stephenplusplus stephenplusplus commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

This is really just two types of changes in many places:

  1. Use...

    if (err) {
      callback(err);
      return;
    }

    ...as opposed to anything else.

  2. Use process.nextTick in two places to simulate an async operation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stephenplusplus
connection: use process.nextTick
0685e8b
stephenplusplus
stephenplusplus reviewed Sep 2, 2014
View reviewed changes
Comment thread lib/common/connection.js Outdated

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus stephenplusplus mentioned this pull request Sep 2, 2014
storage: fix credentials issue. #164
Merged
@ryanseys

ryanseys commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

We should be using setImmediate instead of process.nextTick when executing callbacks. See here for more information.

Pasted here for easy reading:

Callbacks passed to process.nextTick will usually be called at the end of the current flow of execution, and are thus approximately as fast as calling a function synchronously. Left unchecked, this would starve the event loop, preventing any I/O from occurring. setImmediates are queued in the order created, and are popped off the queue once per loop iteration. This is different from process.nextTick which will execute process.maxTickDepth queued callbacks per iteration. setImmediate will yield to the event loop after firing a queued callback to make sure I/O is not being starved.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 2, 2014

Copy link
Copy Markdown
Contributor Author

From the link:

So in a case where you're trying to break up a long running, CPU-bound job using recursion, you would now want to use setImmediate rather than process.nextTick to queue the next iteration as otherwise any I/O event callbacks wouldn't get the chance to run between iterations.

We're just executing a callback. I'm inclined to stick to nextTick for convention reasons, as well as it's the model scenario for async-ifying sync methods according to the docs: process.nextTick.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

process.nextTick has the opportunity to starve the event loop and cause a stack overflow when process.maxTickDepth maxes out and I've seen it happen with streaming before due to a misuse of process.nextTick unresolved in node 0.10.x streams.

We should only use process.nextTick in places where setImmediate isn't available. This is even done in the async library. Considering we are only supporting node 0.10.x for this library, we should be using setImmediate everywhere. For all intents and purposes, process.nextTick and setImmediate will do the same thing in this use case, with setImmediate having the added benefit of not shitting the bed if it's called recursively.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 2, 2014

Copy link
Copy Markdown
Contributor Author

My only reasons for nextTick over setImmediate are based purely on the convention and nextTick documentation. I haven't seen a use of setImmediate to async a sync method, and would feel more comfortable if I did. I do see your points, however I don't think they affect us. It would take a very serious misuse of our library to stack a nextTick queue so high it would choke. Additionally, the async link doesn't do what you say -- it simply uses setImmediate if available in a browser, where there is no nextTick. In this case, setImmediate is much better than setTimeout, 0.

But, yolo. I'll switch it to setImmediate, 'cause why not. It doesn't seem to hurt anything, other than offer a minimal performance loss. Feels weird, but what doesn't in Node?

(@rakyll - feel free to chime in if you prefer it to stick to nextTick)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus
and by nextTick, I mean setImmediate.
60f5256
@stephenplusplus stephenplusplus changed the title connection: use process.nextTick connection: use ~~process.nextTick~~ setImmediate Sep 2, 2014
@ryanseys

ryanseys commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

Yeah before either of us make a decision, I would like to hear what @rakyll
thinks. She knows the Node ropes better than I do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rakyll

rakyll commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

With node v11.0, immediate queue will be able to tick between process ticks. I think that is going to solve the performance concern mentioned above. Otherwise, LGTM.

See this test: https://github.com/joyent/node/blob/857975d5e7e0d7bf38577db0478d9e5ede79922e/test/simple/test-timers-immediate-queue.js

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ryanseys

ryanseys commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

@stephenplusplus You can probably merge this whenever.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Sep 2, 2014

Copy link
Copy Markdown
Contributor Author

Woo! Thanks for saving us, Ryan. setImmediate for the win!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

stephenplusplus added a commit that referenced this pull request Sep 2, 2014
@stephenplusplus
Merge pull request #166 from stephenplusplus/nexttick
f919a6b
connection: use setImmediate to simulate async.
@stephenplusplus
stephenplusplus merged commit f919a6b into googleapis:master Sep 2, 2014
@ryanseys

ryanseys commented Sep 2, 2014

Copy link
Copy Markdown
Contributor

😄 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jul 21, 2021
[Snyk] Fix for 1 vulnerabilities enterstudio/google-cloud-node#108
Open
[Snyk] Fix for 1 vulnerabilities enterstudio/google-cloud-node#111
Open
[Snyk] Security upgrade google-gax from 0.10.8 to 0.14.4 enterstudio/google-cloud-node#113
Open
[Snyk] Fix for 1 vulnerabilities enterstudio/google-cloud-node#115
Open
[Snyk] Fix for 1 vulnerabilities enterstudio/google-cloud-node#116
Open
[Snyk] Fix for 1 vulnerabilities enterstudio/google-cloud-node#121
Open
@sofisl sofisl mentioned this pull request Sep 15, 2022
migrate code from googleapis/nodejs-redis #3360
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Sep 15, 2022
Benjamin E. Coe @JustinBeckwith
build: updated kokoro config for coverage and release-please (#166)
b0f41fa
sofisl pushed a commit that referenced this pull request Sep 27, 2022
@jkwlui @JustinBeckwith
build: add Kokoro configs for autorelease (#166)
93828e1
* build: add Kokoro configs for autorelease

* build: add Kokoro configs for autorelease

* chore: remove CircleCI config
@sofisl sofisl mentioned this pull request Sep 27, 2022
migrate code from googleapis/nodejs-video-intelligence #3374
Closed
4 tasks
@sofisl sofisl mentioned this pull request Oct 12, 2022
migrate code from googleapis/nodejs-bigquery-data-transfer #3399
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Oct 12, 2022
@JustinBeckwith
build: create docs test npm scripts (#166)
f795f3f
@sofisl sofisl mentioned this pull request Oct 13, 2022
migrate code from googleapis/nodejs-memcache #3412
Merged
4 tasks
@GautamSharda GautamSharda mentioned this pull request Feb 3, 2026
migrate code from googleapis/nodejs-logging-winston #7129
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Feb 4, 2026
@jkwlui @JustinBeckwith
Don't publish sourcemaps (#166)
d5fc9e4
This was referenced Feb 4, 2026
migrate code from googleapis/nodejs-logging-bunyan #7136
Closed
migrate code from googleapis/nodejs-logging-bunyan #7137
Closed
migrate code from googleapis/nodejs-logging-bunyan #7138
Merged
migrate code from googleapis/nodejs-datastore #7148
Closed
sofisl pushed a commit that referenced this pull request Feb 5, 2026
@JustinBeckwith @alexander-fenster
chore: do not use npm ci (#166)
e62be71
GautamSharda pushed a commit that referenced this pull request Feb 5, 2026
@DominicKramer
chore: use post-install-check (#166)
0ee0e61
@GautamSharda GautamSharda mentioned this pull request Feb 5, 2026
migrate code from googleapis/nodejs-error-reporting #7169
Closed
4 tasks
sofisl pushed a commit that referenced this pull request Feb 17, 2026
@JustinBeckwith @alexander-fenster
chore: do not use npm ci (#166)
346043e
@sofisl sofisl mentioned this pull request Feb 17, 2026
migrate code from googleapis/nodejs-datastore #7263
Merged
4 tasks
GautamSharda pushed a commit that referenced this pull request Feb 23, 2026
@DominicKramer
chore: use post-install-check (#166)
dd2b347
@GautamSharda GautamSharda mentioned this pull request Feb 23, 2026
migrate code from googleapis/nodejs-error-reporting #7294
Closed
sofisl pushed a commit that referenced this pull request Feb 25, 2026
@zbjornson @stephenplusplus
don't require contentType for bucket.combine (#168)
72c749b
Fixes #166
GautamSharda pushed a commit that referenced this pull request Feb 25, 2026
@release-please
chore: release 2.5.0 (#166)
16c92a7
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
@GautamSharda GautamSharda mentioned this pull request Feb 25, 2026
migrate code from googleapis/nodejs-bigquery-storage #7306
Closed
4 tasks
GautamSharda pushed a commit that referenced this pull request Feb 26, 2026
@DominicKramer
chore: use post-install-check (#166)
3c15d1c
@GautamSharda GautamSharda mentioned this pull request Feb 26, 2026
migrate code from googleapis/nodejs-error-reporting #7308
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Feb 26, 2026
@alexander-fenster @callmehiphop
test: fix get session by name test (#166)
561281e
@GautamSharda GautamSharda mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-bigquery-storage #7496
Merged
4 tasks
GautamSharda pushed a commit that referenced this pull request Mar 5, 2026
@renovate @JustinBeckwith
fix(deps): update dependency gcp-metadata to ^0.7.0 (#166)
3ed0a29
@GautamSharda GautamSharda mentioned this pull request Mar 5, 2026
migrate code from googleapis/nodejs-logging #7514
Merged
4 tasks
@meltsufin meltsufin mentioned this pull request Mar 10, 2026
chore: migrate code from googleapis/nodejs-logging #7550
Merged
GautamSharda pushed a commit that referenced this pull request Mar 11, 2026
@renovate @JustinBeckwith
chore(deps): lock file maintenance (#166)
13d680f
@GautamSharda GautamSharda mentioned this pull request Mar 11, 2026
migrate code from googleapis/nodejs-pubsub #7592
Merged
4 tasks
codyoss pushed a commit that referenced this pull request Mar 12, 2026
@gcf-owl-bot
chore: new owl bot post processor docker image (#166)
bb590ce
gcr.io/repo-automation-bots/owlbot-nodejs:latest@sha256:f93bb861d6f12574437bb9aee426b71eafd63b419669ff0ed029f4b7e7162e3f
@codyoss codyoss mentioned this pull request Mar 12, 2026
migrate code from googleapis/nodejs-precise-date #7594
Merged
GautamSharda pushed a commit that referenced this pull request Mar 12, 2026
@JustinBeckwith
refactor: remove eslint and prettier (#166)
76fff9f
@GautamSharda GautamSharda mentioned this pull request Mar 12, 2026
migrate code from googleapis/nodejs-common #7597
Merged
4 tasks
@GautamSharda GautamSharda mentioned this pull request Mar 23, 2026
migrate code from googleapis/nodejs-bigtable #7852
Merged
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@stephenplusplus @ryanseys @rakyll
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.