CHAI SDK
Version 1.3
|
Since these data exchanges are done over the network, their completion time is variable, and in any case, longer than synchronous calls. Doing it asynchronously avoids freezing the application waiting for the operation completion.
An asynchronous operation is initiated from a call to a method having a suffix ***_Async. Unlike the notification handler which needs being registered, the application gives this method a pointer to a special type of notification handler (suffixed with ***_AsyncReturnHandler) in the argument set, and receives an CPNS::IAsync pointer in return. This pointer is helpful to cancel the operation or identify its instance when a single asynchronous return handler object is shared between multiple concurrent operations.
Additionally, an asynchronous call has a user pointer argument allowing the association of custom data to the operation.
An asynchronous operation can take a while up to the point it is not needed anymore. It is possible to cancel it using CPNS::ICHAI::CancelAsync method.
An AsyncReturnHandler interface usually contains a single method declaration. Independently of the operation success or failure, this method will always be called and provide a pointer to the related CPNS::IAsync, together a flag indicating success or failure, and additional data depending on the nature of the async operation. The user pointer can be retrieved using CPNS::IAsync::GetUserPointer().
Similarly to notifications, a hooked object pointer received from an async return handler must be acquired if the application needs keeping if for a while, and then released when not needed anymore.
Example of asynchronous operation call:
Example of asynchronous return handler: