This library base on Kotlin Coroutines Channel.
Version 2.0 and next based on Kotlin Coroutines SharedFlow
implementation 'com.github.Daniil-Pavenko:coroutines-event-pipe:2.0.0'
- Register event class:
EventPipe.registerEvent(
eventClass: Class<T>,
contextName: String = GLOBAL_CONTEXT, // default
eventDispatcher: CoroutineDispatcher = Dispatchers.Main, // default
eventCallback: suspend (event: T) -> Unit
)- And unregister into
onDestroyoronStopby your logic:
EventPipe.unregisterAllEvents() - for all Events
or
EventPipe.unregisterByContext(contextName: String)- Send event:
EventPipe.send(event: Any, delaySend: Long = 0)- Add package of lib.
- Add package with Event classes.
#EventPipe
-keep class com.dansdev.libeventpipe.** { *; }