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

Introduce setImmediate. #13

Merged
merged 6 commits into from
Dec 6, 2012
Merged

Conversation

jaredcacurak
Copy link
Member

A cross-browser implementation of the new setImmediate API.

@briancavalier
Copy link
Member

Thanks for digging in to this! Just gave it a quick look, but I'll look more tomorrow or Monday.

@jaredcacurak
Copy link
Member Author

It is a has-ified rendition of NobleJS's implementation of setImmediate. How should I accredit them?

installPostMessageImplementation(attachTo);
}
else if (has('message-channel')) {
installMessageChannelImplementation(attachTo);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I losing it or is this function missing? Fwiw, it'd be nice if we didn't need both window.postMessage and MessageChannel. Might be worth testing window.postMessage for speed. From six months ago: https://gist.github.com/2802407

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not losing it, but apparently I did. Somewhere that function was left behind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have some time to test postMessage vs MessageChannel in recent browsers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have our answer: http://jsperf.com/postmessage/6 http://jsperf.com/setimmediate-test/6 http://jsperf.com/postmessage-vs-settimeout

postMessage wins in recent FF, so seems like the better choice now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. no need to add that function, then!

@unscriptable
Copy link
Member

Good set of tests, btw.

setImmediate(handler);
clearImmediate(handler);

tester.assertFalse('setImmediate is not called after clearImmediate is called', changed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, this test would pass even if handler is called in the next turn. IOW, I think this is effectively the same as the very first test case. It's actually impossible to test that handler is never called, but it seems like it'd be good enough to put the assertion in a setTimeout, similar to the test case after this one.

@briancavalier
Copy link
Member

👍

briancavalier added a commit that referenced this pull request Dec 6, 2012
@briancavalier briancavalier merged commit 3401c16 into cujojs:dev Dec 6, 2012
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.

3 participants