on

inline fun <T : SmartAccountEvent> on(crossinline listener: (T) -> Unit): () -> Unit

Subscribes to events of a specific type.

The listener will be called whenever an event of the specified type is emitted. The returned unsubscribe function can be called to remove the listener.

This method is type-safe: the listener parameter is constrained to match the event type through Kotlin's reified type parameter.

Note: This method uses reified generics and cannot be called from Java or Swift. Use addListener for cross-language compatibility.

Return

A function that unsubscribes the listener when called

Example:

val unsubscribe = emitter.on<SmartAccountEvent.WalletConnected> { event ->
println("Wallet ${event.contractId} connected")
}
// Later: unsubscribe()

Parameters

T

The event type to subscribe to

listener

The callback function to invoke on events