Closed gtanczyk closed 7 years ago
That is a great idea, thanks!
By the way in the doc section https://github.com/ysmood/yaku#yakunexttick, I mentioned that you could use mature third party lib such as https://github.com/medikoo/next-tick, it might be better than your workaround.
I published the v0.18.3, please check it out.
It works as expected :+1:
My only concern are any sort of unit tests - anything that relied on sinon and fake timers in particular.
I think I will also contribute this idea to medikoo/next-tick, because using MutationObserver to resolve a promise does not sound good. :-1:
I added a test for it, but it's a very simple one, you can also check the code in 4fc271d.
using MutationObserver to resolve a promise does not sound good
If you dig into it, you will find out it's a good workaround and performs well on most of the browsers. For old browsers, I use https://github.com/YuzuJS/setImmediate.
FF and Chrome are throttling setTimeout to 1000ms in inactive tabs: https://bugzilla.mozilla.org/show_bug.cgi?id=633421 https://bugs.chromium.org/p/chromium/issues/detail?id=66078
I've encountered a problem with flaky test and after a while of debugging it turned out to be a problem with Yaku using setTimeout. Debug log statements happened in exact 1 second time distance, while they were called one after each other. The reason for this was special behavior of Chrome on OSX, where setTimeout is clamped for a window that is not on the top.
The solution is to use native Promise if possible as this is closer to node nextTick.
Quick jsfiddle to play with this: https://jsfiddle.net/0npx5v5r/