hg: mlvm/mlvm/hotspot: 2 new changesets
forax at univ-mlv.fr
Sun Oct 2 05:40:27 PDT 2011
On 10/02/2011 03:03 AM, Mark Roos wrote:
> This is a pretty cool use of coroutines.
> I am trying a similar approach for a web browser base UI and was
> looking for
> a pattern do handle the time out case. So I send something to the UI,
> say open
> a dialog box, and suspend the coroutine. but the UI never responds so
> I have to
> have a loop checking time outs.
Let me explain how AsyncSwing works.
I try use the same coroutine (named uiCoroutine in the code) for all UI
The main coroutine, the one which is implicit do the event pumping,
when an event is received, I yield to the uiCoroutine with the UI event
as argument, the uiCoroutine do the dispatch to the component
and switch back to the main coroutine.
If a call to a blocking IO is done in an event callback, it's done in
so I yield to the main coroutine with a command object (representing the
to complete before yielding back), create a new coroutine and save it as the
new uiCoroutine for the next events and starts the command as an async IO
and go back in the event loop.
> I would like something on the coroutine like suspend but throw an
> exception in
> x ms. I could do it with threads ( suspend a cancelling thread for x
> ms ) but I was
> looking for a light weight approach.
> Any thoughts on how to place a time out on a starved coroutine?
You have two ways to implement a timer. Or you post a special event
the deadline and re-post it if the current time doesn't match the deadline
(this is how javax.swing.Timer works), or you use a ScheduledThreadPool
with only one thread, submit a runnable when you start a timeout and
cancel the corresponding Future if the operation doesn't timeout
or if the runnable is scheduled, you just have to end the coroutine.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mlvm-dev