--
You received this message because you are subscribed to the Google Groups "cujojs" group.
To post to this group, send email to cuj...@googlegroups.com.
To unsubscribe from this group, send email to cujojs+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/cujojs/-/ge1zA1RuFX0J.
For more options, visit https://groups.google.com/groups/opt_out.
To view this discussion on the web visit https://groups.google.com/d/msg/cujojs/-/BViSDYEMy9kJ.
curl.js doesn't wait for next-turn, either. Although this has made the code more complex, it has also made curl faster than other loaders (drastically faster during development).
These corrections have been very trivial. To me, this a no-brainer. I'd much rather have to create an occasional pull request in order to have curl.js be blazing fast than have the opposite situation.It sounds to me like we're in a similar situation with when.js. If so, I'm in favor of same-turn behavior unless acujo.js user has a good case for us to do the opposite. Then we can offer it as an option.
Yes, it’s the latter (as long as they are called in order, and do not interfere with each other e.g. by a thrown exception by the first preventing the second from executing). All of the nextTick-like methods, whether they be process.nextTick, or setImmediate, or setTimeout(, 0), will queue up multiple calls in this way. (Although, see https://github.com/tildeio/rsvp.js/issues/20.)
--
You received this message because you are subscribed to the Google Groups "cujojs" group.
To post to this group, send email to cuj...@googlegroups.com.
To unsubscribe from this group, send email to
cujojs+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/cujojs/-/csS03osEFgEJ.
To unsubscribe from this group, send email to cujojs+u...@googlegroups.com.
After more testing, it's actually around 2x when a fast nextTick like node.js is available, and so far, seems to scale linearly with the number of promises you pile on--I've run tests up to 1 million chained promises, at which point v8 falls over due to memory errors.
Believe me, I do hear you that sometimes you want/need that 2x. Having to degrade to something like setTimeout in old browsers stinks, but thankfully there are faster techniques (read: "hacks") available even back to IE 6. Of course, the multiplier will be more than 2x with those.As I understand it, the real problem is that the behavior in the current tick cannot be guaranteed to be consistent without forcing nextTick for resolutions. For example, if some library hands you a promise, without a guaranteed nextTick, you simply can't tell if it's going to call your callback immediately or later, since the promise may have already resolved. To address Mariusz's suggestion: it's one thing to say "we should just always return unresolved promises", but it seems infeasible to get every developer whose code returns promises to program that way, and we all make mistakes.For some of us, who are comfortable working with promises, it is easy to refactor to deal with that situation. For users who are not as experienced, though, it could be a bad situation, since they might simply test it under one set of conditions and call it done. Then later, under another set of conditions, their app breaks for no apparent reason. Async is hard, so I think it's important to help that situation, if we can.To me, the ideal would be guaranteeing consistent behavior while also providing a very fast implementation.Just to give you an idea of relative test results: In my testing so far, even with the async hit, when.js is still several times faster (without Object.freeze(), which is being removed in 1.6.0 until v8 fixes the perf problem) than jQuery Deferred in every test I've run, and faster than deferred in most of those tests. Both of those libraries are synchronous. Caveat: that's all in node, with a fast nextTick.Another interesting data point: In v8, asynchronous when.js without freeze() is actually quite a bit faster than synchronous when.js with freeze(). So, if your code ran at an acceptable speed using when.js < 1.5.0, then it'll be fine (faster, in fact) in 2.0. Yeah, the v8 freeze() hit is crazy.I feel pretty good about the perf numbers so far, but I do need to do more testing in browsers. If we go async for 2.0, we're still planning to offer an option for sync mode, so you can opt in to that to get the sync speed if your application needs it. Again the thinking is that being consistent and fast by default, and offering a "be careful" but blazingly fast opt-in seems like a good approach
On Tuesday, October 30, 2012 8:09:20 AM UTC-4, johlrogge wrote:
Worth testing against Node 0.9 as well, where nextTick has been substantially sped up.
To unsubscribe from this group, send email to cujojs+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/cujojs/-/ViNMJkjXwyIJ.
To address Mariusz's suggestion: it's one thing to say "we should just always return unresolved promises", but it seems infeasible to get every developer whose code returns promises to program that way, and we all make mistakes.
On Tuesday, October 30, 2012 8:09:20 AM UTC-4, johlrogge wrote:
This is actually not just my suggestion, but golden rule in asynchronous programming. You won't find any asynchronous function in Node.js API that calls callback immediately also you won't find it in any well written package.
Same way if you work with promises, you should never return fulfilled promise from asynchronous function, if it happens it's a bug that needs to be fixed not just mistake, and fixing that by forcing nextTick by promise library internals is I think sloppy route.
On Tuesday, October 30, 2012 7:27:35 PM UTC-4, Mariusz Nowak wrote:
This is actually not just my suggestion, but golden rule in asynchronous programming. You won't find any asynchronous function in Node.js API that calls callback immediately also you won't find it in any well written package.
Yes, we're in agreement on that point. But, it sounds like you've said that any library function that accepts a callback should not call that callback in the current turn. If so, then wouldn't that imply that, since .then() is a library function that accepts a callback, .then() should not call its callbacks in the current turn?
It also seems like never returning a fulfilled promise could make some situations messier. For example, what if a value that would normally be fetched asynchronously is available immediately in a local cache? It seems quite clean to me for a promise-based implementation to simply return a fulfilled promise in that case.
Same way if you work with promises, you should never return fulfilled promise from asynchronous function, if it happens it's a bug that needs to be fixed not just mistake, and fixing that by forcing nextTick by promise library internals is I think sloppy route.
Ah, maybe the difference in viewpoints here is that Domenic is saying that the responsibility of ensuring current-turn callback safety belongs with the promise implementation, whereas you are saying that it belongs with the library (or application) code that is using the promise implementation?Or put another way, ultimately, we seem to agree that ensuring callbacks are not invoked in the current turn is important, but that we disagree on where the responsibility of ensuring that belongs.