import sync const ( num_iterations = 10000 ) struct St { a int } fn get_val_from_chan(ch chan i64) ?i64 { r := <-ch? return r } fn get_val_from_chan2(ch chan i64) ?i64 { r := <-ch or { println('error') return err } return r } // this function gets an array of channels for `i64` fn do_rec_calc_send(chs []chan i64, sem sync.Semaphore) { mut msg := '' for { mut s := get_val_from_chan(chs[0]) or { msg = err.str() break } s++ chs[1] <- s } assert msg == 'channel closed' sem.post() } fn test_channel_array_mut() { mut chs := [chan i64{}, chan i64{cap: 10}] sem := sync.new_semaphore() go do_rec_calc_send(chs, sem) mut t := i64(100) for _ in 0 .. num_iterations { chs[0] <- t t = <-chs[1] } (&sync.Channel(chs[0])).close() orr := &sync.Channel(chs[0]) chs[1].close() ch := chan int{} ch.close() a := ch.cap b := ch.len c := ch[1].cap d := ch[o].len sem.wait() assert t == 100 + num_iterations ch2 := chan mut St{cap: 10} go g(ch2) } fn g(ch chan mut St) { return }