From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- v_windows/v/vlib/sync/channel_opt_propagate_test.v | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 v_windows/v/vlib/sync/channel_opt_propagate_test.v (limited to 'v_windows/v/vlib/sync/channel_opt_propagate_test.v') diff --git a/v_windows/v/vlib/sync/channel_opt_propagate_test.v b/v_windows/v/vlib/sync/channel_opt_propagate_test.v new file mode 100644 index 0000000..a7e26fe --- /dev/null +++ b/v_windows/v/vlib/sync/channel_opt_propagate_test.v @@ -0,0 +1,39 @@ +import sync + +const ( + num_iterations = 10000 +) + +fn get_val_from_chan(ch chan i64) ?i64 { + r := <-ch ? + return r +} + +// this function gets an array of channels for `i64` +fn do_rec_calc_send(chs []chan i64, mut sem sync.Semaphore) { + mut msg := '' + for { + mut s := get_val_from_chan(chs[0]) or { + msg = err.msg + break + } + s++ + chs[1] <- s + } + assert msg == 'channel closed' + sem.post() +} + +fn test_channel_array_mut() { + mut chs := [chan i64{}, chan i64{cap: 10}] + mut sem := sync.new_semaphore() + go do_rec_calc_send(chs, mut sem) + mut t := i64(100) + for _ in 0 .. num_iterations { + chs[0] <- t + t = <-chs[1] + } + chs[0].close() + sem.wait() + assert t == 100 + num_iterations +} -- cgit v1.2.3