1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sync/select: allow push of literals and calculated expressions (#6429)

This commit is contained in:
Uwe Krüger
2020-09-20 03:50:09 +02:00
committed by GitHub
parent c781a5f245
commit 4ae88c69ac
7 changed files with 96 additions and 24 deletions

View File

@@ -36,32 +36,23 @@ fn test_select() {
go do_send_int(chi)
go do_send_byte(chb)
go do_send_i64(chl)
mut channels := [&sync.Channel(chi), &sync.Channel(recch), &sync.Channel(chl), &sync.Channel(chb)]
directions := [sync.Direction.pop, .push, .pop, .pop]
mut sum := i64(0)
mut rl := i64(0)
mut ri := int(0)
mut rb := byte(0)
mut sl := i64(0)
mut objs := [voidptr(&ri), &sl, &rl, &rb]
for _ in 0 .. 1200 {
idx := sync.channel_select(mut channels, directions, mut objs, -1)
match idx {
0 {
select {
ri := <-chi {
sum += ri
}
1 {
recch <- sl {
sl++
}
2 {
rl = <-chl {
sum += rl
}
3 {
rb := <-chb {
sum += rb
}
else {
println('got $idx (timeout)')
}
}
}
// Use Gauß' formula for the first 2 contributions