Sleep

7 views
Skip to first unread message

mmoossen

unread,
Sep 4, 2009, 11:39:50 AM9/4/09
to Oni - embedded structured concurrency
hello world!

all i want to do is sleep(1000), but it does not seem as i expect :(

better said, i want to open an (async) JQuery UI dialog in the
windows.unload event, the problem is that without any help JQuery
createas the dialog and set the callback but does not wait for user
input, so the execution continues and the unload event finishes,
before the user had a chance to do something, and so the browser just
continues unloading the page :(

here is the code:
<code>
$(window).unload( function () {
var ready = false;
// open nice dialog
$('#dialog').dialog({
autoOpen: true,
width: 600,
buttons: {
"Ok": function() {
ready = true;
$(this).dialog("close");
},
"Cancel": function() {
ready = true;
$(this).dialog("close");
}
}
});
// wait until dialog is closed
while(!ready) {
// here ONI uses too much CPU and the browser complains
Eval(Sleep(1000));
}
});
</code>

normally you can use native alert or confirm dialogs that will block
the browser until the user does something, but these dialogs are ugly
and limited in functionality...

any idea how to achieve this with (or without) oni??

thanks
Michael

Alexander Fritze

unread,
Sep 4, 2009, 7:32:37 PM9/4/09
to oni-...@googlegroups.com
Hi Michael,

When you execute an Oni expression from JavaScript using Eval(), the
Eval() call returns immediately, while the Oni expression executes in
the background. That is why your loop spins with high CPU and you get
the browser complaining.

Because event handlers aren't aware of Oni, you cannot really use Oni
to achieve a delayed return; events are 'external signals' as far as
Oni is concerned.

Regards,
Alex
Reply all
Reply to author
Forward
0 new messages