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

Fix order of nextTick processing to match nodejs #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChristophKaser
Copy link

Nodejs processes callbacks added by process.nextTick in a queue (=> LIFO order). Lowjs uses a stack (=>FIFO order).
This causes issues, e.g in readable-streams, where I had 'readable' events after the 'end' event, which in turn caused a deadlock in code unprepared for this event order.

Demo code to check lowjs and nodejs behavior:

function a () {
    console.log('a');
    process.nextTick(b);
    process.nextTick(b);
}

function b () {
    console.log('b');
    process.nextTick(c, '1');
    process.nextTick(c, '2');
}

function c (arg) {
    console.log('c', arg);
}

a();

This PR fixes the order used by lowjs by inserting new callbacks at the bottom of the stack. While this is suboptimal for a large number of callbacks, in real world code the number of callbacks usually is not that large, so the O(n²) behaviour of the insertion method should not matter.

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

Successfully merging this pull request may close these issues.

1 participant