/ Events
DEMO | DOWNLOAD | DEPLOY | SEARCH
Login

Schedule

function setTimeout(callback:function, millisecs:number):number
function setInterval(callback:function, millisecs:number):number
function clearInterval(id:number):void

Events are scheduled using setTimeout/setInterval/clearInterval, just as in ecmascript.

One difference is that we need to explicitly call update() so that events will be serviced:

function foo() {
    puts("FOO:");
}
setInterval(foo, 1000);
update(-1);

The call to update(-1) causes foo to be called once a second.


Update

function update(options:number|object=void):number

update processes scheduled events.

  • With no arguments, update will process all events in the queue then return.
  • If a number argument is given, it is treated as the minTime option below.
  • If an object argument is given, it may contain any of the following options:

OptionDescription
maxEventsMaximum number of events to process
maxPassesMaximum passes through event queue
minTimeMinimum milliseconds before returning, or -1 to loop forever (Default is 0)
sleepSleep time between event checks in milliseconds (Default is 1)

Events are processed until one of minTime, maxEvents, or maxPasses is exceeded.

The returned value is the number of events processed.

For more details see Reference


Info

Info.event = function (id:number=void):array|object

In Jsi we can use Info.event() to query queued events:

function foo() {
    puts("FOO: " + i++);
    if (i>=3) exit(0);
}
var i=0, id = setInterval(foo,1000);
var evs = Info.event();
for (var i in evs) {
  puts('EV(' + i + '): ' + Info.event(evs[i]).toString());
}
update();
EV(0): { builtin:false, count:0, initial:1000, once:false, type:"timer", when:1000 }
FOO: 0
FOO: 1
FOO: 2

This returns value is:

  • With no arg, the list of ids for queued events.
  • With one arg, the information for the given event id.

For more details see Info