diff --git a/cover.html b/cover.html
deleted file mode 100644
index 106e984..0000000
--- a/cover.html
+++ /dev/null
@@ -1,248 +0,0 @@
-
-
-
-
-
-
-
package bus
-
-import (
- "fmt"
- "reflect"
- "sync"
-
- "github.com/gopatchy/metadata"
-)
-
-type Bus struct {
- mu sync.Mutex
- keyViews map[string]map[uintptr]chan<- any
- typeViews map[string]map[uintptr]chan<- any
-}
-
-func NewBus() *Bus {
- return &Bus{
- keyViews: map[string]map[uintptr]chan<- any{},
- typeViews: map[string]map[uintptr]chan<- any{},
- }
-}
-
-func (b *Bus) Announce(t string, obj any) {
- key := getObjKey(t, obj)
-
- b.mu.Lock()
- defer b.mu.Unlock()
-
- announce(obj, b.keyViews[key])
- announce(obj, b.typeViews[t])
-}
-
-func (b *Bus) Delete(t string, id string) {
- key := getKey(t, id)
-
- b.mu.Lock()
- defer b.mu.Unlock()
-
- for _, c := range b.keyViews[key] {
- close(c)
- }
-
- delete(b.keyViews, key)
-
- announce(id, b.typeViews[t])
-}
-
-func (b *Bus) SubscribeKey(t, id string, initial any) <-chan any {
- key := getKey(t, id)
-
- b.mu.Lock()
- defer b.mu.Unlock()
-
- ret := make(chan any, 100)
-
- ret <- initial
-
- if _, has := b.keyViews[key]; !has {
- b.keyViews[key] = map[uintptr]chan<- any{}
- }
-
- b.keyViews[key][chanID(ret)] = ret
-
- return ret
-}
-
-func (b *Bus) SubscribeType(t string, initial any) <-chan any {
- b.mu.Lock()
- defer b.mu.Unlock()
-
- ret := make(chan any, 100)
-
- ret <- initial
-
- if _, has := b.typeViews[t]; !has {
- b.typeViews[t] = map[uintptr]chan<- any{}
- }
-
- b.typeViews[t][chanID(ret)] = ret
-
- return ret
-}
-
-func (b *Bus) UnsubscribeKey(t, id string, c <-chan any) {
- key := getKey(t, id)
-
- b.mu.Lock()
- defer b.mu.Unlock()
-
- if cw, has := b.keyViews[key][chanID(c)]; has {
- close(cw)
- delete(b.keyViews[key], chanID(c))
- }
-
- if len(b.keyViews[key]) == 0 {
- delete(b.keyViews, key)
- }
-}
-
-func (b *Bus) UnsubscribeType(t string, c <-chan any) {
- b.mu.Lock()
- defer b.mu.Unlock()
-
- if cw, has := b.typeViews[t][chanID(c)]; has {
- close(cw)
- delete(b.typeViews[t], chanID(c))
- }
-
- if len(b.typeViews[t]) == 0 {
- delete(b.typeViews, t)
- }
-}
-
-func getObjKey(t string, obj any) string {
- return getKey(t, metadata.GetMetadata(obj).ID)
-}
-
-func getKey(t string, id string) string {
- return fmt.Sprintf("%s:%s", t, id)
-}
-
-func announce(obj any, chans map[uintptr]chan<- any) {
- for id, c := range chans {
- select {
- case c <- obj:
- default:
- close(c)
- delete(chans, id)
- }
- }
-}
-
-func chanID(c <-chan any) uintptr {
- return reflect.ValueOf(c).Pointer()
-}
-
-
-
-
-
-
diff --git a/cover.out b/cover.out
deleted file mode 100644
index 887ba16..0000000
--- a/cover.out
+++ /dev/null
@@ -1,27 +0,0 @@
-mode: atomic
-github.com/gopatchy/bus/bus.go:17.20,22.2 1 2
-github.com/gopatchy/bus/bus.go:24.43,32.2 5 5
-github.com/gopatchy/bus/bus.go:34.43,40.36 4 1
-github.com/gopatchy/bus/bus.go:40.36,42.3 1 1
-github.com/gopatchy/bus/bus.go:44.2,46.30 2 1
-github.com/gopatchy/bus/bus.go:49.66,59.37 6 5
-github.com/gopatchy/bus/bus.go:59.37,61.3 1 4
-github.com/gopatchy/bus/bus.go:63.2,65.12 2 5
-github.com/gopatchy/bus/bus.go:68.63,76.36 5 3
-github.com/gopatchy/bus/bus.go:76.36,78.3 1 3
-github.com/gopatchy/bus/bus.go:80.2,82.12 2 3
-github.com/gopatchy/bus/bus.go:85.58,91.48 4 5
-github.com/gopatchy/bus/bus.go:91.48,94.3 2 4
-github.com/gopatchy/bus/bus.go:96.2,96.31 1 5
-github.com/gopatchy/bus/bus.go:96.31,98.3 1 4
-github.com/gopatchy/bus/bus.go:101.55,105.47 3 3
-github.com/gopatchy/bus/bus.go:105.47,108.3 2 3
-github.com/gopatchy/bus/bus.go:110.2,110.30 1 3
-github.com/gopatchy/bus/bus.go:110.30,112.3 1 3
-github.com/gopatchy/bus/bus.go:115.42,117.2 1 5
-github.com/gopatchy/bus/bus.go:119.41,121.2 1 16
-github.com/gopatchy/bus/bus.go:123.54,124.27 1 11
-github.com/gopatchy/bus/bus.go:124.27,125.10 1 10
-github.com/gopatchy/bus/bus.go:126.17,126.17 0 10
-github.com/gopatchy/bus/bus.go:127.11,129.21 2 0
-github.com/gopatchy/bus/bus.go:134.35,136.2 1 23
diff --git a/go.mod b/go.mod
index 72d8b1f..47882e0 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/gopatchy/bus
go 1.19
require (
- github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe
+ github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5
github.com/stretchr/testify v1.8.2
go.uber.org/goleak v1.2.1
)
diff --git a/go.sum b/go.sum
index a31b162..1025f52 100644
--- a/go.sum
+++ b/go.sum
@@ -6,6 +6,8 @@ github.com/gopatchy/metadata v0.0.0-20230424223338-33e58fee42bf h1:HKCbhVEpC3++y
github.com/gopatchy/metadata v0.0.0-20230424223338-33e58fee42bf/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe h1:xPnlis/qCAYoxHx9tow1P4pO17c8JH/Hs/lHDmZej/Q=
github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
+github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5 h1:b66b4DOGTqDuw4hbxHSp0WbhXr/xAMaiFkU6iCi4nDg=
+github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=