ofDelayedFunc improved
This commit is contained in:
parent
a89b395510
commit
08e28c8c1a
14
of.go
14
of.go
@ -12,19 +12,7 @@ func Of[T any](values ...T) <-chan T {
|
||||
|
||||
// OfDelayed behaves like Of but with a pre-defined delay between each value
|
||||
func OfDelayed[T any](delay time.Duration, values ...T) <-chan T {
|
||||
out := make(chan T, len(values))
|
||||
|
||||
go func(out chan T, values []T) {
|
||||
for i, value := range values {
|
||||
out <- value
|
||||
if i < len(values)-1 {
|
||||
time.Sleep(delay)
|
||||
}
|
||||
}
|
||||
close(out)
|
||||
}(out, values)
|
||||
|
||||
return out
|
||||
return OfDelayedFunc(func(value T) time.Duration { return delay }, values...)
|
||||
}
|
||||
|
||||
// OfDelayedFunc behaves like OfDelayed but accepts a function to determine the delay
|
||||
|
Loading…
Reference in New Issue
Block a user