Syntax
|
eventhandler(myq); // handle all tasks with name myq eventhandler(myq,*); //handle all tasks with name myq eventhandler(myq,?); // handle all tasks with name myq, // all types, concurrently for each type eventhandler(myq,mtyp)
|
Text
|
Event handler is a piece of caravan code that is linked to queue very closely. It is created by adding a eventhandler statement in a caravan template which is written to dispatch the queueed tasks.
The eventhandler statement is almost identical to the queue declaration syntax.
Eventhandler keyword is used to specify that the code following it should be activated when an event of the specified type occurs. It is the responsibility of this code to reset the event by deleting it from queue. A object _event of type queue also gets created automatically. The eventhandler can be thought of as a thread that wakes up whenever _event(item) becomes ready and executes user code repeatedly until all events are cleared . It then goes back into suspended state until another event occurs.
Create a handler for specified type and subtype where type is any expected typename and subtype is either ? or * or a name of an expected subtype.
|
Sample
|
example : Simple event handler
<caravan> // expecting an item of type "incoming" with qualifier "news" eventhandler (incoming.news);// handle incoming news eventhandler (incoming.*);// handle all incoming data or eventhandler (incoming.&question);// handle incoming data by distinct subtypes.
file nf = _event(item) ; // handle it like a file -- could have been anything though. table lateststory=news.stories; // put it into database and clear event . lateststory(subject)=nf(getline) ; // assumes first line in file is the subject lateststory(story)=_event(item) ; _event(deleteItem) ; clears event and goes back to check for another event , sleeps if none </caravan>
PLEASE REFER TO OBJECTS--> QUEUES FOR EXAMPLES.
|
Quick Reference
|
|
Properties
|
suspend
|
Home
Back
|
|