AtomsQueue<T> class
Namespace: Arlecchino.Atoms.Collections · Assembly: Arlecchino.Core
A queue held as one piece of application state, joined at the back and left from the front. It is touched only by the drawing thread, so background work hands its item over with FrameThread.Post.
public abstract class AtomsQueue<T> : IReadableAtom<IReadOnlyList<T>>
Implements IReadableAtom<IReadOnlyList<T><T>>
Constructors
| Member | Summary |
|---|---|
AtomsQueue(IReadOnlyList<T>) | Creates the queue. |
Properties
| Member | Summary |
|---|---|
Count | How many are waiting. |
IsEmpty | Whether nothing is waiting. |
RecordsHistory | Whether changes of this queue enter the undo history. |
Value | What is waiting now, front first, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below. |
Methods
| Member | Summary |
|---|---|
Clear() | Drops everything waiting. An empty queue changes nothing. |
Dequeue() | Takes the one at the front, and throws when nothing is waiting. |
Enqueue(T) | Puts something at the back. |
Enqueue(IReadOnlyList<T>) | Puts several at the back at once, in the order given. One notification, one frame and one undo step for the lot. |
GetEnumerator() | Walks what is waiting, front first, so foreach over the queue itself reads the way it does over a list. Reach for AtomsQueue.Value where a sequence is what is wanted, LINQ included. |
Peek() | Reads the one at the front without taking it, and throws when nothing is waiting. |
Reset(IReadOnlyList<T>) | Replaces what is waiting in one go, for a queue that is rebuilt rather than worked through — a plan worked out again, a batch reordered. Contents equal to what is already there change nothing. |
Subscribe(Action) | Calls back whenever what is waiting changes. |
TryDequeue(out T) | Takes the one at the front without throwing when nothing is waiting. |
TryPeek(out T) | Reads the one at the front without taking it or throwing. |
Constructors in detail
AtomsQueue(IReadOnlyList<T>)
public AtomsQueue(IReadOnlyList<T> initial);
Creates the queue.
Parameters
| Name | Type | Description |
|---|---|---|
initial | IReadOnlyList<T><T> | What is already waiting, front first; empty when omitted. It is copied, not held. |
Properties in detail
Count
public int Count { get; }
How many are waiting.
Type int
IsEmpty
public bool IsEmpty { get; }
Whether nothing is waiting.
Type bool
RecordsHistory
public abstract bool RecordsHistory { get; }
Whether changes of this queue enter the undo history.
Type bool
Value
public IReadOnlyList<T> Value { get; }
What is waiting now, front first, as a live view rather than a copy. It is read-only all the way down, so every change goes through the members below.
Type IReadOnlyList<T><T>
Methods in detail
Clear()
public void Clear();
Drops everything waiting. An empty queue changes nothing.
Dequeue()
public T Dequeue();
Takes the one at the front, and throws when nothing is waiting.
Returns T — What was at the front.
Enqueue(T)
public void Enqueue(T item);
Puts something at the back.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What to add. |
Enqueue(IReadOnlyList<T>)
public void Enqueue(IReadOnlyList<T> items);
Puts several at the back at once, in the order given. One notification, one frame and one undo step for the lot.
Parameters
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<T><T> | What to add. Adding none changes nothing. |
GetEnumerator()
public List<T> GetEnumerator();
Walks what is waiting, front first, so foreach over the queue itself reads the way it does over a list. Reach for AtomsQueue.Value where a sequence is what is wanted, LINQ included.
Returns Enumerator<T><T> — The enumerator, which throws when the queue changes while it is being walked.
Peek()
public T Peek();
Reads the one at the front without taking it, and throws when nothing is waiting.
Returns T — What is at the front.
Reset(IReadOnlyList<T>)
public void Reset(IReadOnlyList<T> items);
Replaces what is waiting in one go, for a queue that is rebuilt rather than worked through — a plan worked out again, a batch reordered. Contents equal to what is already there change nothing.
Parameters
| Name | Type | Description |
|---|---|---|
items | IReadOnlyList<T><T> | What should be waiting instead, front first. |
Subscribe(Action)
public IDisposable Subscribe(Action listener);
Calls back whenever what is waiting changes.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Action | What to run on change. |
Returns IDisposable — Dispose it to stop listening.
TryDequeue(out T)
public bool TryDequeue(out T item);
Takes the one at the front without throwing when nothing is waiting.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What was at the front, when there was one. |
Returns bool — true when something was taken.
TryPeek(out T)
public bool TryPeek(out T item);
Reads the one at the front without taking it or throwing.
Parameters
| Name | Type | Description |
|---|---|---|
item | T | What is at the front, when there is one. |
Returns bool — true when there was one.