invokeOnCompletion

abstract fun invokeOnCompletion(
    handler: CompletionHandler
): DisposableHandle
(source)

Overrides Job.invokeOnCompletion

Registers handler that is synchronously invoked once on completion of this continuation. When continuation is already complete, then the handler is immediately invoked with continuation’s exception or null. Otherwise, handler will be invoked once when this continuation is complete.

The resulting DisposableHandle can be used to dispose the registration of this handler and release its memory if its invocation is no longer needed. There is no need to dispose the handler after completion of this continuation. The references to all the handlers are released when this continuation completes.

Installed handler should not throw any exceptions. If it does, they will get caught, wrapped into CompletionHandlerException, and rethrown, potentially causing crash of unrelated code.