2020-09-05 02:36:20 +03:00
|
|
|
module builtin
|
|
|
|
|
2021-02-07 13:42:24 +03:00
|
|
|
// ChanState describes the result of an attempted channel transaction.
|
2020-09-05 02:36:20 +03:00
|
|
|
enum ChanState {
|
|
|
|
success
|
|
|
|
not_ready // push()/pop() would have to wait, but no_block was requested
|
|
|
|
closed
|
|
|
|
}
|
|
|
|
|
2021-02-07 13:42:24 +03:00
|
|
|
/*
|
|
|
|
The following methods are only stubs.
|
|
|
|
The real implementation is in `vlib/sync/channels.v`
|
|
|
|
*/
|
2020-09-05 02:36:20 +03:00
|
|
|
|
2021-02-07 13:42:24 +03:00
|
|
|
// close closes the channel for further push transactions.
|
|
|
|
// closed channels cannot be pushed to, however they can be popped
|
|
|
|
// from as long as there is still objects available in the channel buffer.
|
2020-09-05 02:36:20 +03:00
|
|
|
pub fn (ch chan) close() {}
|
|
|
|
|
2021-02-07 13:42:24 +03:00
|
|
|
// try_pop returns `ChanState.success` if an object is popped from the channel.
|
|
|
|
// try_pop effectively pops from the channel without waiting for objects to become available.
|
|
|
|
// Both the test and pop transaction is done atomically.
|
2020-09-05 02:36:20 +03:00
|
|
|
pub fn (ch chan) try_pop(obj voidptr) ChanState {
|
|
|
|
return .success
|
|
|
|
}
|
|
|
|
|
2021-02-07 13:42:24 +03:00
|
|
|
// try_push returns `ChanState.success` if the object is pushed to the channel.
|
|
|
|
// try_push effectively both push and test if the transaction `ch <- a` succeeded.
|
|
|
|
// Both the test and push transaction is done atomically.
|
2020-09-05 02:36:20 +03:00
|
|
|
pub fn (ch chan) try_push(obj voidptr) ChanState {
|
|
|
|
return .success
|
|
|
|
}
|