v2 / vlib / v / tests / concurrency / thread_wait_ptr_test.v
18 lines · 16 sloc · 319 bytes · fc640f7ce00ff61ee32f04ffce6dccb73472fc9c
Raw
1import math { sqrt }
2import time
3
4fn get_hypot(a f64, b f64) f64 {
5 time.sleep(100 * time.millisecond)
6 c := sqrt(a * a + b * b)
7 return c
8}
9
10fn test_main() {
11 mut arr := &[]thread f64{}
12 for num in 1 .. 1000 {
13 g := go get_hypot(num, num)
14 arr << g
15 }
16 result := arr.wait()
17 assert result[0] == 1.4142135623730951
18}
19