Hi, all!
i seem to have setTimeout() working in v8, using pthreads for the
threading and usleep() (from unistd.h) for the delay. Before i post
the code and ask for critiques regarding the my use of v8::Locker/
Unlocker, i need to implement one missing feature. To do that, i need
to answer this question:
when setTimeout() is called like: setTimeout( "some code", timeval )
(as opposed to setTimeout(Function,timeval)), must "some code" be
treated as a function body or is it to be eval()ed?
:-?
Here's a short demo:
var sleeptime = 5; // time to sleep while waiting for loops
var dms = 1200; // delay between setTimeout() loops, in ms
var count = 0; // loops count
var reps = 8; // max number of loops to run.
function foofunc()
{
if( ++count <= reps )
{
print("Scheduling foofunc() in",dms," miliseconds.");
setTimeout( foofunc, dms );
}
else
{
print("Loop limit reached. foofunc() not looping.");
}
}
print("sleeping",sleeptime,"seconds:",new Date());
foofunc();
sleep(sleeptime); // sleep() unlocks v8, so the timeouts can run
print("slept",sleeptime,"seconds:",new Date());
print("Calling foofunc() manually once:");
foofunc(); // trying to force a collision/overlap in exit of the app
vs. timeouts.
Output:
step...@jareth:~/cvs/v8-juice/trunk/src/client/shell$ ./v8-juice-shell
js/sleep.js
sleeping 5 seconds: Fri Sep 11 2009 20:12:12 GMT+0200 (CEST)
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
slept 5 seconds: Fri Sep 11 2009 20:12:18 GMT+0200 (CEST)
Calling foofunc() manually once:
Scheduling foofunc() in 1200 miliseconds.
that final scheduled foofunc() call never fires because the app exits;
the important part there is that it doesn't segfault, either.
Once more, with 'var reps = 3':
step...@jareth:~/cvs/v8-juice/trunk/src/client/shell$ ./v8-juice-shell
js/sleep.js
sleeping 5 seconds: Fri Sep 11 2009 20:25:31 GMT+0200 (CEST)
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
Scheduling foofunc() in 1200 miliseconds.
Loop limit reached. foofunc() not looping.
slept 5 seconds: Fri Sep 11 2009 20:25:36 GMT+0200 (CEST)
Calling foofunc() manually once:
Loop limit reached. foofunc() not looping.
:)
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---