Sometimes you do not want to wait for an operation to finish. If you use external I/O callbacks, you can cancel a pending operation. However, you must ensure that no other thread is currently using the context in which the operation you want to cancel runs. This includes callback handlers. So your external event loop must either be halted or otherwise it must be guaranteed that no installed I/O callbacks are run for this context.
gpgme_cancelattempts to cancel a pending operation in the context ctx. This only works if you use the global event loop or your own event loop.
If you use the global event loop, you must not call
gpgme_waitduring cancellation. After successful cancellation, you can call
gpgme_wait(optionally waiting on ctx), and the context ctx will appear as if it had finished with the error code
If you use your an external event loop, you must ensure that no I/O callbacks are invoked for this context (for example by halting the event loop). On successful cancellation, all registered I/O callbacks for this context will be unregistered, and a
GPGME_EVENT_DONEevent with the error code
GPG_ERR_CANCELwill be signaled.
The function returns an error code if the cancellation failed (in this case the state of ctx is not modified).