| 1 | module main |
| 2 | |
| 3 | struct In[T] { |
| 4 | source chan T |
| 5 | } |
| 6 | |
| 7 | fn emit[T](s In[T], ar []T) { |
| 8 | for _, i in ar { |
| 9 | s.source <- i |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | fn from[T](ar []T) In[T] { |
| 14 | s := In[T]{} |
| 15 | |
| 16 | spawn emit(s, ar) |
| 17 | |
| 18 | return s |
| 19 | } |
| 20 | |
| 21 | fn (i In[T]) get() T { |
| 22 | return <-i.source |
| 23 | } |
| 24 | |
| 25 | fn test_main() { |
| 26 | v := from[int]([1]).get() |
| 27 | |
| 28 | assert v == 1 |
| 29 | } |
| 30 |