change Generate to call g not on construction, but on first Stream

This commit is contained in:
faiface
2017-07-26 01:13:49 +02:00
parent d714e60c27
commit df7184506d

View File

@@ -37,8 +37,15 @@ func Callback(f func()) Streamer {
//
// Generate does not propagate errors from the generated Streamers.
func Generate(g func() Streamer) Streamer {
s := g()
var (
s Streamer
first = true
)
return StreamerFunc(func(samples [][2]float64) (n int, ok bool) {
if first {
s = g()
first = false
}
if s == nil {
return 0, false
}