summaryrefslogtreecommitdiff
path: root/vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl')
-rw-r--r--vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl b/vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl
new file mode 100644
index 000000000..4249588a3
--- /dev/null
+++ b/vendor/github.com/ugorji/go/codec/gen-enc-chan.go.tmpl
@@ -0,0 +1,27 @@
+{{.Label}}:
+switch timeout{{.Sfx}} := z.EncBasicHandle().ChanRecvTimeout; {
+case timeout{{.Sfx}} == 0: // only consume available
+ for {
+ select {
+ case b{{.Sfx}} := <-{{.Chan}}:
+ {{ .Slice }} = append({{.Slice}}, b{{.Sfx}})
+ default:
+ break {{.Label}}
+ }
+ }
+case timeout{{.Sfx}} > 0: // consume until timeout
+ tt{{.Sfx}} := time.NewTimer(timeout{{.Sfx}})
+ for {
+ select {
+ case b{{.Sfx}} := <-{{.Chan}}:
+ {{.Slice}} = append({{.Slice}}, b{{.Sfx}})
+ case <-tt{{.Sfx}}.C:
+ // close(tt.C)
+ break {{.Label}}
+ }
+ }
+default: // consume until close
+ for b{{.Sfx}} := range {{.Chan}} {
+ {{.Slice}} = append({{.Slice}}, b{{.Sfx}})
+ }
+}