ofDelayedFunc further improved

This commit is contained in:
Timon Ringwald 2022-02-17 09:18:37 +01:00
parent 08e28c8c1a
commit d5afefc540

2
of.go
View File

@ -20,13 +20,13 @@ func OfDelayedFunc[T any](delayFunc func(value T) time.Duration, values ...T) <-
out := make(chan T, len(values))
go func(out chan T, values []T) {
defer close(out)
for i, value := range values {
out <- value
if i < len(values)-1 {
time.Sleep(delayFunc(value))
}
}
close(out)
}(out, values)
return out