Eventing

Besides standard flow control instructions mentioned before, urbiscript provides additional instructions supporting parallelism. Another parallel oriented mechanism of urbiscript are built-in events.

urbi at

//at-onleave
var x = false;
tag: at(x)    //without tag, it will be impossible to pause/stop execution of the code
  echo("x")  //here we do not put any separator
onleave
  echo("!x");  

urbi whenever

//changing values:
var x;
x = true; //prints "x" once
x = true; //nothing happens
x = false;//prints "!x" once
//whenever-else
x = false;
tag:whenever (x) 
{
echo("ping");
sleep(1);
}
else
{
echo("pong");
sleep(1);
},
x = true; //prints ping every 1s
x = false;//stops printing ping and starts printing pong every 1s

urbi every

// every
tag:every(1s)
  echo("Are you there?"),
 
// print  "Are you there?" every 1s until tag is stoped or freezed

urbi wait

// waituntil
var x = false;
{
waituntil(x); // blocks flow control in this scope, until x becomes true
echo("Bye");
},
x = true; // unblocks flow control in previous scope, "Bye" is printed once
// Events - building and emitting
var myEvent = Event.new(); //declare new event
at(myEvent?)
  echo("ping at");
whenever(myEvent?) {
echo("ping whenever");
sleep(100ms);
},
myEvent!; //emit event
//"ping at" is emitted once, "ping whenever" is emitted once
myEvent! ~ 300ms; //emit event for 0.3 second.
//"ping at" is emitted once, "ping whenever" is emitted three times

More examples you can find in the URBI documentation LINK.

 

 

EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 0.8.0, 27.04.2016

FLASH Documentation