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