An example

An application that performs asynchronous database updates might include the routine do_update, where do_update calls all of the Client-Library routines that are necessary to perform a database update.

The main application calls do_update asynchronously and go on with its other work.

When called, do_update replaces the main application’s completion callback routine with its own callback (so that the main application’s callback routine is not triggered by low-level asynchronous completions). It then proceeds with the work of the update. To perform the update, do_update calls several Client-Library routines, including ct_send and ct_results, which behave asynchronously. When each asynchronous routine completes, it triggers do_update’s completion callback.

When do_update has finished the update operation, it reinstalls the main application’s completion callback and calls ct_wakeup with function as its own function ID. This triggers the main application’s completion callback, letting the main application know that do_update has completed.