v2 / vlib / v / tests / concurrency / shared_option_test.v
23 lines · 20 sloc · 272 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct ABC {
2mut:
3 s string
4}
5
6fn test_shared_option() {
7 shared abc := foo() or { panic('scared') }
8 rlock abc {
9 println(abc)
10 assert abc.s == 'hello'
11 }
12}
13
14fn foo() ?ABC {
15 mut a := ABC{}
16 a.bar()?
17 return a
18}
19
20fn (mut a ABC) bar() ? {
21 a.s = 'hello'
22 println(a.s)
23}
24