Skip to content

ivanbadia/coroutines-eventbus

Repository files navigation

Introduction

Simple implementation of an event bus using kotlin coroutines shared flow

How to Use

Create the event:

class OrderWasCreated (override val occurredOn: OffsetDateTime = OffsetDateTime.now()) : DomainEvent

Create the subscriber:

class OrderWasCreatedSubscriber : DomainEventSubscriber<OrderWasCreated> {
    override fun consume(event: OrderWasCreated) {
        println("Order created")
    }
}

Register the subscriber in the event bus:

val eventBus = SharedFlowEventBus()
                        .subscribe(OrderWasCreatedSubscriber())

Publish the event:

eventBus.publish(OrderWasCreated())

About

Event bus based on Kotlin coroutines

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages