本文整理汇总了Golang中github.com/keep94/gofunctional2/functional.Stream.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Stream.Close方法的具体用法?Golang Stream.Close怎么用?Golang Stream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/keep94/gofunctional2/functional.Stream
的用法示例。
在下文中一共展示了Stream.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Consume
// Consume fetches the values. s is a Stream of T.
func (b *Buffer) Consume(s functional.Stream) {
defer s.Close()
b.idx, b.err = readStreamIntoSlice(s, b.buffer, b.addrFunc)
if b.err == functional.Done {
b.err = nil
}
}
示例2: Consume
// Consume prints all Entry values that s emits to stdout. On error, prints
// the error encountered and halts.
func (p Printer) Consume(s functional.Stream) {
var entry Entry
err := s.Next(&entry)
for ; err == nil; err = s.Next(&entry) {
fmt.Println(&entry)
}
if err != functional.Done {
fmt.Printf("Error happened: %v\n", err)
s.Close()
}
}
示例3: FirstOnly
// FirstOnly reads the first value from stream storing it in ptr.
// FirstOnly closes the stream.
// FirstOnly returns emptyError if no values were on stream.
func FirstOnly(stream functional.Stream, emptyError error, ptr interface{}) (err error) {
defer func() {
closeError := stream.Close()
if err == nil {
err = closeError
}
}()
err = stream.Next(ptr)
if err == functional.Done {
err = emptyError
return
}
return
}