From 965594ea867fecb57e33b36ae114b4bb9acd1930 Mon Sep 17 00:00:00 2001 From: eliaskohout Date: Mon, 20 Jan 2025 20:27:59 +0000 Subject: [PATCH] rm distributer --- src/internal/util/Distributer.go | 37 -------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/internal/util/Distributer.go diff --git a/src/internal/util/Distributer.go b/src/internal/util/Distributer.go deleted file mode 100644 index 46f5a01..0000000 --- a/src/internal/util/Distributer.go +++ /dev/null @@ -1,37 +0,0 @@ -package util - -type Distributer[T IClone[T]] struct { - queue chan T - hooks []func(T) -} - -func (d *Distributer[T]) Init() { - d.queue = make(chan T, 100) - d.hooks = make([]func(T), 0) -} - -// Distribute a copy of an item to every hook that has described to this -// Collector. -func (d *Distributer[T]) Publish(item T) { - d.queue <- item -} - -// Add a new hook to the Collector. The hook will be called async whenever a -// new item is published. -func (d *Distributer[T]) Subscribe(hook func(T)) { - d.hooks = append(d.hooks, hook) - if len(d.hooks) == 1 { - go d.runner() - } -} - -// Will be started to run async when Subscribe is first called. Whenever -// Publish is called the runner will distribute a clone of the new item to -// every hook. -func (d *Distributer[T]) runner() { - for val := range d.queue { - for _, f := range d.hooks { - go f(val.Clone()) - } - } -}