On 19 Mar 2011 14:43, "Breton Slivka" <[email protected]> wrote: > > > I can't think of a single way to simulate setTimeout in ES5. Correct me if > > I'm wrong, but I don't think ES5 exposes a single way of defining a > > mechanism like: > > -- > > var x = 4; > > function f(){ x = 5; print(x); } > > timer(f, 1); > > print(f); > > -- > > Such that it would output 4 before 5. That's what I meant with "didn't have > > any asynchronism", fwiw. > > while (!programHasQuit()) { > > timers= (function () { > var timers = []; > var id=0; > timer=function (f,t) { > timers.push({func:f, interval:t, id:id++}); > return id; > } > return timers; > }) > > runScript("myscript.js"); > handleEvents(timers,otherevents); > > } > > > and there you go, in pure JS. If this is a gui program, you may expose > a queue of GUI events to this "master script", but I believe that the > event loop is best left to the embedding. If setTimeout etc are > implemented in the core JS engine, the JS engine can simply expose the > pool of timers as some data structure to the embedded C/C++ program to > do with what you wish- The standard would presumably specify some > guidelines for this.
That only works if the host environment isn't waiting for you to finish / wait / sleep / yield / etc. But yeah, ok :) - peter
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

