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

Modify defer to use native task queue via promise if available #2154

Closed
wants to merge 2 commits into from
Closed

Modify defer to use native task queue via promise if available #2154

wants to merge 2 commits into from

Conversation

midnight-wonderer
Copy link

Hi there
I wonder if we can use native defer when run on environment that has Promise interface available?
Take advantage from browser optimized task queue.

@midnight-wonderer
Copy link
Author

Hi @jdalton
I can not get this to pass TravisCI but I glad you got the idea.

This approach allow some room for browser to optimize in particular area.
In my opinion the accuracy should come first in setTimeout optimiztion. (Best effort for accuracy)
In the other hand promise optimization will focus on performance and maybe memory consumption.

Please refer to ES6 draft
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-jobs-and-job-queues
where they introduce the idea of task queue in ES6 to use in Promise.

For the inconsistent:
Native defer will be triggered before setTimeout.
Please refer to some test on node.js repo
nodejs/node-v0.x-archive#7714 (comment)

For the polyfill promise that comply to Promises/A+ specification (not jQuery one) my best guess is that it also use setTimeout to simulate the effect. (AFAIK no other mechanism to accomplish this in ES5) So for polyfill Promise it will do essentially the same as setTimeout 1.

@midnight-wonderer
Copy link
Author

I don't know what to do with the code in this case but this will do just to demonstrate the idea.
Should I just add lint directive to tell that Promise is a global object? Maybe in .eslintrc file?

I'm open to hear review / suggestion / recommendation from you guys.

@megawac
Copy link
Collaborator

megawac commented Apr 20, 2015

I'd be more keen on using setImmediate over the Promise based implementation, but I can relate to the arguments in #466. Either way I would be skeptical of using a Promise based implementation of defer to avoid issues from Promise polyfills

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

Successfully merging this pull request may close these issues.

3 participants