MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / GoodStream

Function GoodStream

go/test/testing.go:32–54  ·  view source on GitHub ↗

GoodStream checks whether there's errors in `stream`

(stream chan interface{})

Source from the content-addressed store, hash-verified

30
31// GoodStream checks whether there's errors in `stream`
32func GoodStream(stream chan interface{}) (bool, string) {
33 lastResp := list.New()
34 keepSize := 10
35
36 for rsp := range stream {
37 switch rsp.(type) {
38 case error:
39 var ss []string
40 for e := lastResp.Front(); e != nil; e = e.Next() {
41 if s, ok := e.Value.(string); ok {
42 ss = append(ss, s)
43 }
44 }
45 return false, fmt.Sprintf("%v: %s", rsp, strings.Join(ss, "\n"))
46 }
47 lastResp.PushBack(rsp)
48 if lastResp.Len() > keepSize {
49 e := lastResp.Front()
50 lastResp.Remove(e)
51 }
52 }
53 return true, ""
54}

Calls

no outgoing calls