fixed bugs

This commit is contained in:
Tordarus 2022-02-09 12:17:49 +01:00
parent 969bd51948
commit cc9a4bb6ca
2 changed files with 8 additions and 3 deletions

View File

@ -9,14 +9,14 @@ import (
// WriteInto writes all given values into the channel ch. // WriteInto writes all given values into the channel ch.
// Is is a shorthand for Forward(ch, AsChan(values...)) // Is is a shorthand for Forward(ch, AsChan(values...))
func WriteInto[T any](ch chan<- T, values ...T) { func WriteInto[T any](ch chan<- T, values ...T) {
Forward(ch, AsChan(values...)) Forward(ch, Of(values...))
} }
// WriteIntoDelayed writes all given values into the channel ch. // WriteIntoDelayed writes all given values into the channel ch.
// It sleeps after every write for the given amount of time. // It sleeps after every write for the given amount of time.
// It is a shorthand for Forward(ch, AsChanDelayed(time, values...)) // It is a shorthand for Forward(ch, AsChanDelayed(time, values...))
func WriteIntoDelayed[T any](ch chan<- T, delay time.Duration, values ...T) { func WriteIntoDelayed[T any](ch chan<- T, delay time.Duration, values ...T) {
Forward(ch, AsChanDelayed(delay, values...)) Forward(ch, OfDelayed(delay, values...))
} }
// WriteIntoWriter reads all values from ch and writes them via fmt.Fprintln to all writers // WriteIntoWriter reads all values from ch and writes them via fmt.Fprintln to all writers

7
of.go
View File

@ -1,8 +1,13 @@
package channel package channel
import (
"context"
"time"
)
// Of returns a channel containing all values // Of returns a channel containing all values
func Of[T any](values ...T) <-chan T { func Of[T any](values ...T) <-chan T {
return AsChanDelayed(0, values...) return OfDelayed(0, values...)
} }
// OfDelayed behaves like Of but with a pre-defined delay between each value // OfDelayed behaves like Of but with a pre-defined delay between each value