mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sync/channels: provide .cap and .len() (#6104)
This commit is contained in:
@@ -250,6 +250,15 @@ if ch.pop(&m) {
|
||||
}
|
||||
```
|
||||
|
||||
There are also methods `try_push()` and `try_pop()` which return immediatelly with the return value `.not_ready` if the transaction
|
||||
cannot be performed without waiting. The return value is of type `sync.TransactionState` which can also be
|
||||
`.success` or `.closed`.
|
||||
|
||||
To monitor a channel there is a method `len()` which returns the number of elements currently in the queue and the attribute
|
||||
`cap` for the queue length. Please be aware that in general `channel.len() > 0` does not guarantee that the next
|
||||
`pop()` will succeed without waiting, since other threads may already have "stolen" elements from the queue. Use `try_pop()` to
|
||||
accomplish this kind of task.
|
||||
|
||||
The select call is somewhat tricky. The `channel_select()` function needs three arrays that
|
||||
contain the channels, the directions (pop/push) and the object references and
|
||||
a timeout of type `time.Duration` (`time.infinite` or `-1` to wait unlimited) as parameters. It returns the
|
||||
|
||||
Reference in New Issue
Block a user