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

Making async.forever run... forever =) #622

Closed
wants to merge 1 commit into from
Closed

Making async.forever run... forever =) #622

wants to merge 1 commit into from

Conversation

rdegges
Copy link

@rdegges rdegges commented Sep 12, 2014

Previously, if async.forever was called, since it wasn't using setImmediate --
the max call stack size would be exceeded rather quickly.

This fix introduces setImmediate behavior to prevent user-generated tasks from
starving the event loop of resources.

Fixes #437.

Previously, if async.forever was called, since it wasn't using `setImmediate` --
the max call stack size would be exceeded rather quickly.

This fix introduces setImmediate behavior to prevent user-generated tasks from
starving the event loop of resources.

Fixes #437.
@aearly
Copy link
Collaborator

aearly commented Sep 15, 2014

That will happen if the function you pass to forever isn't async. Have you tried adding a async.nextTick(callback); in that function?

@rdegges
Copy link
Author

rdegges commented Sep 23, 2014

Hey @aearly -- unfortunately that doesn't work :( take this code snippet for instance:

var async = require('async');

var i = 0;
async.forever(
  function(next) {
    console.log('hi', i);
    i++;
    async.nextTick(next);
  }, function() { }
);

If you run that you'll get:

(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.

RangeError: Maximum call stack size exceeded

@aearly
Copy link
Collaborator

aearly commented Sep 25, 2014

Then do what it says -- try setImmediate instead.

@rdegges
Copy link
Author

rdegges commented Sep 28, 2014

That's what I did -- that's also what the PR changes ^^

It makes sense to me to merge this in -- this way the behavior is guaranteed to run as expected for developers.

If you think it shouldn't -- feel free to close. Sorry for the confusion.

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

Successfully merging this pull request may close these issues.

async.forever ... isn't ?!
2 participants