Skip to content

An in-process and in-memory PubSub, Broadcast, EventBus or Fanout implementation with type-safe topics implemented with generics. Respects context.

License

Notifications You must be signed in to change notification settings

egemengol/spread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spread

GoDoc GitHub

An in-process and in-memory PubSub, Broadcast, EventBus or Fanout implementation with type-safe topics implemented with generics. Respects context.

Subscriber Patterns

These patterns can be used for a given topic at the same time with multiple instances.

Channel-based

Every recvChan gets its own channel for reading.

var topic *spread.Topic[int]

recvChan, removeRecvChan, err := topic.GetRecvChannel(20)
for number := range recvChan {
    fmt.Printf("Got from channel: %d\n", number)
}

Asynchronous

var topic *spread.Topic[int]

topic.HandleAsync(func(_ctx context.Context, number int) {
    fmt.Printf("Handling in async handler: %d\n", number)
})

Synchronous

This blocks the topic's progress so better to keep it non-blocking.

var topic *spread.Topic[int]

topic.HandleSync(func(number int) {
    fmt.Printf("Handling in sync handler: %d\n", number)
})

Performance Characteristics

  • Every topic has a inbound channel with a dedicated goroutine for broadcasting.
  • Synchronous handlers in HandleSync get executed in this goroutine.
  • Asynchronous handlers or receiver channels that cannot keep up (with full buffers) get eliminated from the subscribers.
  • Publishing is the same as sending to a buffered channel, blocks when full.

About

An in-process and in-memory PubSub, Broadcast, EventBus or Fanout implementation with type-safe topics implemented with generics. Respects context.

Topics

Resources

License

Stars

Watchers

Forks

Languages