setNotificationHandler

fun <T : Notification> setNotificationHandler(method: Method, handler: (notification: T) -> Deferred<Unit>)(source)

Registers a handler to invoke when this protocol object receives a notification with the given method.

Note that this will replace any previous notification handler for the same method.

Handlers may run concurrently after initialization and are cancelled cooperatively, so always re-throw CancellationException. Replacing a built-in control-method handler (ping, notifications/cancelled, notifications/progress, notifications/initialized) with slow code degrades connection liveness. Replacing notifications/cancelled in particular disables inbound request cancellation entirely, since that handler is what cancels the running job.