Class OperationQueue
- Namespace
- Punchclock
- Assembly
- Punchclock.dll
OperationQueue is the core of PunchClock, and represents a scheduler for deferred actions, such as network requests. This scheduler supports scheduling via priorities, as well as serializing requests that access the same data.
The queue allows a fixed number of concurrent in-flight operations at a time. When there are available "slots", items are dispatched as they come in. When the slots are full, the queueing policy starts to apply.
The queue, similar to Akavache's KeyedOperationQueue, also allows keys to be specified to serialize operations - if you have three "foo" items, they will wait in line and only one "foo" can run. However, a "bar" and "baz" item can run at the same time as a "foo" item.
- Inheritance
-
Operation
Queue
- Implements
- Extension Methods
Constructors
OperationQueue(int)
Initializes a new instance of the Operation
Parameters
maximumConcurrentintThe maximum number of concurrent operations.
OperationQueue(int, bool, int?)
Initializes a new instance of the Operation
Parameters
maximumConcurrentintThe maximum number of concurrent operations.
randomizeEqualPriorityboolIf true, randomizes execution order among equal-priority items across different keys.
seedint?Optional seed to make randomization deterministic for tests.
Methods
Dispose()
Dispose(bool)
Disposes managed resources that are disposable and handles cleanup of unmanaged items.
Parameters
isDisposingboolIf we are disposing managed resources.
EnqueueObservableOperation<T>(int, Func<IObservable<T>>)
This method enqueues an action to be run at a later time, according to the scheduling policies (i.e. via priority).
public IObservable<T> EnqueueObservableOperation<T>(int priority, Func<IObservable<T>> asyncCalculationFunc)
Parameters
priorityintHigher priorities run before lower ones.
asyncCalculationFuncFunc<IObservable<T>>The async method to execute when scheduled.
Returns
- IObservable<T>
The result of the async calculation.
Type Parameters
TThe type of item for the observable.
EnqueueObservableOperation<T>(int, string, Func<IObservable<T>>)
This method enqueues an action to be run at a later time, according to the scheduling policies (i.e. via priority and key).
public IObservable<T> EnqueueObservableOperation<T>(int priority, string key, Func<IObservable<T>> asyncCalculationFunc)
Parameters
priorityintHigher priorities run before lower ones.
keystringItems with the same key will be run in order.
asyncCalculationFuncFunc<IObservable<T>>The async method to execute when scheduled.
Returns
- IObservable<T>
The result of the async calculation.
Type Parameters
TThe type of item for the observable.
EnqueueObservableOperation<T, TDontCare>(int, string, IObservable<TDontCare>, Func<IObservable<T>>)
This method enqueues an action to be run at a later time, according to the scheduling policies (i.e. via priority and key).
public IObservable<T> EnqueueObservableOperation<T, TDontCare>(int priority, string key, IObservable<TDontCare> cancel, Func<IObservable<T>> asyncCalculationFunc)
Parameters
priorityintThe priority of operation. Higher priorities run before lower ones.
keystringA key to apply to the operation. Items with the same key will be run in order.
cancelIObservable<TDontCare>A observable which if signalled, the operation will be cancelled.
asyncCalculationFuncFunc<IObservable<T>>The async method to execute when scheduled.
Returns
- IObservable<T>
The result of the async calculation.
Type Parameters
TThe type of item for the observable.
TDontCareUsed to allow any observable type.
PauseQueue()
This method pauses the dispatch queue. Inflight operations will not be canceled, but new ones will not be processed until the queue is resumed.
Returns
- IDisposable
A Disposable that resumes the queue when disposed.
SetMaximumConcurrent(int)
Sets the maximum level of concurrency for the operation queue.
Parameters
maximumConcurrentintThe maximum amount of concurrency.
ShutdownQueue()
Shuts down the queue and notifies when all outstanding items have been processed.
Returns
- IObservable<Unit>
An Observable that will signal when all items are complete.