Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Events : Callback Functions

Callback Functions
Callback functions are an essential component of your program’s code. They do the actual application-specific work of responding to events—processing inbound messages, timer events and I/O conditions.
For example, inbound messages carry information from other program processes. As each message arrives, the receiving program must take appropriate actions, such as these:
 
In essence, an event object represents a request to run program-specific code whenever a matching event occurs. Event interest persists until the program explicitly cancels its interest by destroying the event object.
While an event object exists, the event that it specifies can occur many times; consequently the event object reappears in its event queue as matching events occur and recur. The callback function runs once for each occurrence of the event (that is, each time the event appears in its queue, and the program dispatches it).
Dispatch Thread
A callback function always runs in the thread that dispatched its event.
For example, the dispatcher convenience feature (see Dispatcher Threads) runs callback functions outside of program control (usually, in a separate dispatcher thread). In a contrasting example, when a program explicitly calls a dispatch function, the callback function runs in the thread that called the dispatch function.
Closure Data
When creating an event, a program can supply closure data. Rendezvous software neither examines nor modifies the closure. Instead, the event creation call stores the data with the event, and presents it to the event callback function.
A similar mechanism passes closure data to ledger review callback functions.
In C and C++ programs, the closure argument is a pointer (of type void*); it can point to any type of data.
In Java programs, the closure argument is a reference to any object.
Return Promptly
 

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved