package main import ( "fmt" "git.pyer.club/kingecg/gostream" ) type TReadAble[T any] struct { gostream.ReadStream[T] sended int E []T } func (tr *TReadAble[T]) StartRead() chan T { // var d T // if tr.sended < len(tr.E) { // d = tr.E[tr.sended] // tr.sended++ // return &d // } // return nil ch := make(chan T) go func() { for i := 0; i < len(tr.E); i++ { ch <- tr.E[i] } close(ch) }() return ch } func main() { x := &TReadAble[int]{ gostream.ReadStream[int]{}, 0, []int{1, 2, 3, 4, 5}, } x.ReadStream.IReadAble = x // x.OnData(func(d int) { // fmt.Println(d) // }) fmt.Println(x.Read()) fmt.Println(x.Read()) fmt.Println(x.Read()) fmt.Println(x.Read()) // for t := tr.DoRead(); t != nil; t = tr.DoRead() { // fmt.Println(*t) // } // tr.OnData(func(d int) { // fmt.Println("tr.OnData", d) // }) select {} }