diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/vlib/sync/channel_array_mut_test.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/old/vlib/sync/channel_array_mut_test.v')
-rw-r--r-- | v_windows/v/old/vlib/sync/channel_array_mut_test.v | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/sync/channel_array_mut_test.v b/v_windows/v/old/vlib/sync/channel_array_mut_test.v new file mode 100644 index 0000000..bfd53a1 --- /dev/null +++ b/v_windows/v/old/vlib/sync/channel_array_mut_test.v @@ -0,0 +1,35 @@ +const ( + num_iterations = 10000 +) + +struct St { +mut: + dummy i64 + dummy2 u32 + dummy3 i64 + n int + dummy4 int +} + +// this function gets an array of channels for `St` references +fn do_rec_calc_send(chs []chan mut St) { + for { + mut s := <-chs[0] or { break } + s.n++ + chs[1] <- s + } +} + +fn test_channel_array_mut() { + mut chs := [chan mut St{cap: 1}, chan mut St{}] + go do_rec_calc_send(chs) + mut t := &St{ + n: 100 + } + for _ in 0 .. num_iterations { + chs[0] <- t + t = <-chs[1] + } + chs[0].close() + assert t.n == 100 + num_iterations +} |