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{})
| 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. |
| 260 | func 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 | } |
searching dependent graphs…