Put a new element into a queue.
- if there are readers blocked on this thread,
the first reader will be woken to process the data
- if there are no readers currently blocking,
but the queue still have enough spare space,
the new element will be placed in the queue,
and put will return immediately without suspension
- if the queue is already full, the behavior is determined by
the kind argument provided on queue creation:
- Unbounded: the queue has unbounded size, so can never be full
- DiscardOldest: the oldest element in the queue is discarded
- DiscardLatest: the argument of put is silently discarded,
and put will have not effect
Although put is an async function,
if will not suspend unless the queue is Blocking and already full.
So for Unbounded/DiscardOldest/DiscardLatest,
it is safe to assume that put is actually synchronous.
For context where async function is not allowed, use try_put instead.
put itself never fails. But for Blocking queues,
put may be cancelled before it succeed,
in this case put will fail with a cancellation error.
It is guaranteed that the element will be added to the queue
if and only if put return normally.
If the queue is already closed, put will fail immediately.
If the queue is a blocking queue, and is closed while put is blocking,
put will also fail immediately.