MCPcopy Create free account
hub / github.com/eapache/channels / Unwrap

Function Unwrap

channels.go:260–277  ·  view source on GitHub ↗

Unwrap takes a SimpleOutChannel and uses reflection to pipe it to a typed native channel for easy integration with existing channel sources. Output can be any writable channel type (chan or chan<-). It panics if the output is not a writable channel, or if a value is received that cannot be sent on t

(input SimpleOutChannel, output interface{})

Source from the content-addressed store, hash-verified

258// It panics if the output is not a writable channel, or if a value is received that cannot be sent on the
259// output channel.
260func Unwrap(input SimpleOutChannel, output interface{}) {
261 t := reflect.TypeOf(output)
262 if t.Kind() != reflect.Chan || t.ChanDir()&reflect.SendDir == 0 {
263 panic("channels: input to Unwrap must be readable channel")
264 }
265
266 go func() {
267 v := reflect.ValueOf(output)
268 for {
269 x, ok := <-input.Out()
270 if !ok {
271 v.Close()
272 return
273 }
274 v.Send(reflect.ValueOf(x))
275 }
276 }()
277}

Callers 1

TestUnwrapFunction · 0.85

Calls 2

OutMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestUnwrapFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…