Skip to content

Commit

Permalink
chore: add constructor func for ReplayObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Oct 24, 2023
1 parent 82e361e commit 299ffb1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/observable/channel/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ type replayObservable[V any] struct {
replayObservers []observable.Observer[V]
}

// NewReplayObservable returns a new ReplayObservable with a replay buffer size
// of n and the corresponding publish channel to notify it of new values.
func NewReplayObservable[V any](
ctx context.Context, n int,
) (observable.ReplayObservable[V], chan<- V) {
obsvbl, publishCh := NewObservable[V]()
return Replay[V](ctx, n, obsvbl), publishCh
}

// Replay returns an observable which replays the last n values published to the
// source observable to new observers, before publishing new values.
func Replay[V any](
Expand Down

0 comments on commit 299ffb1

Please sign in to comment.