kewpie_007 New member

Joined: 25 Jun 2012 Posts: 1 Location: China
|
Posted: Mon Jun 25, 2012 2:26 am Post subject: yield execution in javascipt |
|
|
This post is to discuss whether the capability of yielding execution in javascript is helpful and welcomed.
I hit an async-to-sync issue when to implement some synchronous API using asynchronous API. After asynchronous API is called, I want to wait for result for a while and return then. However, the result is set in callback way, and it's impossible to wait by busy while loop, because otherwise callback would never be called.
If javascript could conditionally yield its execution to browser, and then browser would be able to schedule other workable tasks and invoke callbacks. Once condition is met, execution can resume from yield point again.
In this way, nothing will be blocked, whereas, we can achieve some synchronous program style.
I have tried this out in Chromium (w/ necessary change), and it works pretty well.
Wondering if you have any comment. |
|