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

Async-Improvement #6

Closed
StarpTech opened this issue May 20, 2013 · 3 comments
Closed

Async-Improvement #6

StarpTech opened this issue May 20, 2013 · 3 comments
Milestone

Comments

@StarpTech
Copy link

Hello Dan,
my name is Dustin Deus I´m software engineer from Germany. I like your array library lazy.js.I have one observation when I use lazy.js with NodeJs you use for async operations the "setTimeout" function with a variable timeout. This works very well when somebody want a timeout but if you just want a fast async iteration I recommend you to use the much more efficient method "process.nextTick" and for all DOM stuff you can use the setImmediate API with great fallbacks. https://github.com/NobleJS/setImmediate
I think this change will increase you library in async speed very well.

@dtao
Copy link
Owner

dtao commented May 20, 2013

Thanks for the suggestion, @BeCreative-Germany! One of my next priorities for Lazy.js is to make it more Node-friendly. Thus far it's been developed primarily for the browser, with Node support sort of just "there"; this sounds like a great step towards that. I will look into it very soon.

@dtao
Copy link
Owner

dtao commented Jun 17, 2013

This issue has lain dormant for a while. I did some research, and it actually looks like using process.nextTick is not a good idea as it will block any pending I/O events from happening. (In my mind, the whole point of asynchronous iteration would be to allow important work—e.g., I/O work—to continue while iterating.)

I'm probably going to remove the logic to use process.nextTick in the next version of Lazy. I will still use setImmediate, where available (IE, Node.js). For browsers I may also consider using the postMessage hack; however, it might make more sense to just stick with setImmediate since web developers can always include a library like NobleJS/setImmediate if they want to support more browsers.

@dtao
Copy link
Owner

dtao commented Jan 3, 2014

This has been settled for a while now:

  • Lazy doesn't use nextTick as this can take precedence over I/O, which sort of defeats the purpose of async iteration (the idea is to not hold up other operations)
  • If interval is undefined, Lazy will use setImmediate if available
  • Otherwise it falls back to setTimeout (w/ a default timeout of 0)

I was just leaving this issue open because... well, for no good reason, actually.

@dtao dtao closed this as completed Jan 3, 2014
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

No branches or pull requests

2 participants