Class SharedQueue<T>
A thread-safe shared queue implementation.
Implements
Inherited Members
Namespace: RabbitMQ.Util
Assembly: RabbitMQ.Client.WinRT.dll
Syntax
public class SharedQueue<T> : IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T |
Fields
| Improve this Doc View Sourcem_isOpen
Flag holding our current status.
Declaration
protected bool m_isOpen
Field Value
Type | Description |
---|---|
System.Boolean |
m_queue
The shared queue.
Declaration
protected Queue<T> m_queue
Field Value
Type | Description |
---|---|
System.Collections.Queue<T> |
Remarks
Subclasses must ensure appropriate locking discipline when accessing this field. See the implementation of Enqueue, Dequeue.
m_waiting
Declaration
protected Queue<TaskCompletionSource<T>> m_waiting
Field Value
Type | Description |
---|---|
System.Collections.Queue<System.Threading.Tasks.TaskCompletionSource<T>> |
Methods
| Improve this Doc View SourceClose()
Close the queue. Causes all further Enqueue() operations to throw EndOfStreamException, and all pending or subsequent Dequeue() operations to throw an EndOfStreamException once the queue is empty.
Declaration
public void Close()
Dequeue()
Retrieve the first item from the queue, or block if none available
Declaration
public T Dequeue()
Returns
Type | Description |
---|---|
T |
Remarks
Callers of Dequeue() will block if no items are available until some other thread calls Enqueue() or the queue is closed. In the latter case this method will throw EndOfStreamException.
Dequeue(Int32, out T)
Retrieve the first item from the queue, or return nothing if no items are available after the given timeout
Declaration
public bool Dequeue(int millisecondsTimeout, out T result)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | millisecondsTimeout | |
T | result |
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
If one or more items are present on the queue at the time the call is made, the call will return immediately. Otherwise, the calling thread blocks until either an item appears on the queue, or millisecondsTimeout milliseconds have elapsed.
Returns true in the case that an item was available before the timeout, in which case the out parameter "result" is set to the item itself.
If no items were available before the timeout, returns false, and sets "result" to null.
A timeout of -1 (i.e. System.Threading.Timeout.Infinite) will be interpreted as a command to wait for an indefinitely long period of time for an item to become available. Usage of such a timeout is equivalent to calling Dequeue() with no arguments. See also the MSDN documentation for System.Threading.Monitor.Wait(object,int).
If no items are present and the queue is in a closed state, or if at any time while waiting the queue transitions to a closed state (by a call to Close()), this method will throw EndOfStreamException.
DequeueAsync()
Asynchronously retrieves the first item from the queue.
Declaration
public Task<T> DequeueAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> |
DequeueNoWait(T)
Retrieve the first item from the queue, or return defaultValue immediately if no items are available
Declaration
public T DequeueNoWait(T defaultValue)
Parameters
Type | Name | Description |
---|---|---|
T | defaultValue |
Returns
Type | Description |
---|---|
T |
Remarks
If one or more objects are present in the queue at the time of the call, the first item is removed from the queue and returned. Otherwise, the defaultValue that was passed in is returned immediately. This defaultValue may be null, or in cases where null is part of the range of the queue, may be some other sentinel object. The difference between DequeueNoWait() and Dequeue() is that DequeueNoWait() will not block when no items are available in the queue, whereas Dequeue() will.
If at the time of call the queue is empty and in a closed state (following a call to Close()), then this method will throw EndOfStreamException.
Enqueue(T)
Place an item at the end of the queue.
Declaration
public void Enqueue(T o)
Parameters
Type | Name | Description |
---|---|---|
T | o |
Remarks
If there is a thread waiting for an item to arrive, the waiting thread will be woken, and the newly Enqueued item will be passed to it. If the queue is closed on entry to this method, EndOfStreamException will be thrown.
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable<T>.GetEnumerator()
Implementation of the IEnumerable interface, for permitting SharedQueue to be used in foreach loops.
Declaration
IEnumerator<T> IEnumerable<T>.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
IEnumerable.GetEnumerator()
Implementation of the IEnumerable interface, for permitting SharedQueue to be used in foreach loops.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |