chore: bump http kit (#817)

* use new httpkit runner

* refactor out last httpkit changes

* fix timeout defaults

* fix wrong time input - closes #819
This commit is contained in:
Hayden 2024-03-01 18:07:03 -06:00 committed by GitHub
parent 77b4d594af
commit 2867a05c92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 121 additions and 67 deletions

View file

@ -2,6 +2,7 @@
package eventbus
import (
"context"
"sync"
"github.com/google/uuid"
@ -43,24 +44,29 @@ func New() *EventBus {
}
}
func (e *EventBus) Run() {
func (e *EventBus) Run(ctx context.Context) error {
if e.started {
panic("event bus already started")
}
e.started = true
for event := range e.ch {
e.mu.RLock()
arr, ok := e.subscribers[event.event]
e.mu.RUnlock()
for {
select {
case <-ctx.Done():
return nil
case event := <-e.ch:
e.mu.RLock()
arr, ok := e.subscribers[event.event]
e.mu.RUnlock()
if !ok {
continue
}
if !ok {
continue
}
for _, fn := range arr {
fn(event.data)
for _, fn := range arr {
fn(event.data)
}
}
}
}