Le 13/10/2013 21:39, Jonas Sicking a écrit :
Ok, this thread is clearly heading off the deep end. Let me clear up a
few points of confusion:
* You can not wrap a truly synchronous library around an asynchronous
API. Spinning the event loop gets you close, but breaks
run-to-completion. Furthermore, spinning the event loop is irrelevant
as we don't have an API to do that, nor are we planning to introduce
one.
* yield only works within generators in JS.
To be honest, I feel generators will be interoperably deployed
cross-browser long before sync APIs in workers. V8 and SpiderMonkey
already have generators. I'm not entirely sure it's 100% compliant in
SpiderMonkey yet, but for sure it's being actively worked on and should
be soon if not yet.
* You could solve the use case of compile-to-JS for code that uses
sync APIs using yield. However it requires changing all functions into
generators, and all function calls into yield* statements.
all? as is "all function in the application"? that sounds like a too
violent constraint, especially if a small proportion of the code uses
sync functions. Maybe only the functions that may call a sync function
need to be changed to generators... oh... hmm... I don't know.
Taking the liberty to cc Alon Zakai to ask for his expert opinion on
this topics.
That comes
at a performance overhead that is significant enough as to make it an
unacceptable solution (several times slower in current
implementations).
I guess this point depends on the previous one. Given that compile-to-JS
has wind behind these days, generators may benefits from optimizations.
* yield would not solve the use-case of allowing libraries that use
features from the main thread as it, again, would require a rewrite of
all code that directly or indirectly uses that library to change all
functions into generators and all function calls into yield*.
I think this point is about interoperability between main thread and
worker. I don't remember this point being discussed too much yet.
What about exposing both async and sync APIs to workers?
David