ofDelayedFunc further improved
This commit is contained in:
parent
08e28c8c1a
commit
d5afefc540
2
of.go
2
of.go
@ -20,13 +20,13 @@ func OfDelayedFunc[T any](delayFunc func(value T) time.Duration, values ...T) <-
|
|||||||
out := make(chan T, len(values))
|
out := make(chan T, len(values))
|
||||||
|
|
||||||
go func(out chan T, values []T) {
|
go func(out chan T, values []T) {
|
||||||
|
defer close(out)
|
||||||
for i, value := range values {
|
for i, value := range values {
|
||||||
out <- value
|
out <- value
|
||||||
if i < len(values)-1 {
|
if i < len(values)-1 {
|
||||||
time.Sleep(delayFunc(value))
|
time.Sleep(delayFunc(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(out)
|
|
||||||
}(out, values)
|
}(out, values)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
Loading…
Reference in New Issue
Block a user