100-go-mistakes/11-testing/86-sleeping/main.go
2021-12-27 15:56:17 +01:00

30 lines
408 B
Go

package main
type Handler struct {
n int
publisher publisher
}
type publisher interface {
Publish([]Foo)
}
func (h Handler) getBestFoo(someInputs int) Foo {
foos := getFoos(someInputs)
best := foos[0]
go func() {
if len(foos) > h.n {
foos = foos[:h.n]
}
h.publisher.Publish(foos)
}()
return best
}
func getFoos(inputs int) []Foo {
return make([]Foo, 100)
}
type Foo struct{}