remove iterator related changes

This commit is contained in:
2024-08-22 16:15:09 +01:00
parent 3f38749085
commit baf4630ce7
3 changed files with 1 additions and 72 deletions

View File

@@ -3,7 +3,6 @@ package gubgub
import (
"context"
"fmt"
"iter"
"sync"
)
@@ -121,32 +120,6 @@ func (t *AsyncTopic[T]) Subscribe(fn Subscriber[T]) error {
return nil
}
// Feed allows the usage of for/range to consume future published messages. The supporting subscriber will eventually be discarded after you exit the for loop.
func (t *AsyncTopic[T]) Feed() iter.Seq[T] {
feed := make(chan T, 1)
done := make(chan struct{})
t.Subscribe(func(msg T) bool {
select {
case feed <- msg:
return true
case <-done:
close(feed)
return false
}
})
return func(yield func(T) bool) {
defer close(done)
for msg := range feed {
if !yield(msg) {
return
}
}
}
}
type AsyncTopicOptions struct {
onClose func()
onSubscribe func(count int)