SerialDispatchQueueScheduler
public class SerialDispatchQueueScheduler : SchedulerType
Abstracts the work that needs to be performed on a specific dispatch_queue_t
. It will make sure
that even if concurrent dispatch queue is passed, it’s transformed into a serial one.
It is extremely important that this scheduler is serial, because certain operator perform optimizations that rely on that property.
Because there is no way of detecting is passed dispatch queue serial or concurrent, for every queue that is being passed, worst case (concurrent) will be assumed, and internal serial proxy dispatch queue will be created.
This scheduler can also be used with internal serial queue alone.
In case some customization need to be made on it before usage,
internal serial queue can be customized using serialQueueConfiguration
callback.
-
Undocumented
Declaration
Swift
public typealias TimeInterval = Foundation.TimeInterval
-
Undocumented
Declaration
Swift
public typealias Time = Date
-
Declaration
Swift
public var now: Date { get }
Return Value
Current time.
-
Constructs new
SerialDispatchQueueScheduler
with internal serial queue namedinternalSerialQueueName
.Additional dispatch queue properties can be set after dispatch queue is created using
serialQueueConfiguration
.Declaration
Swift
public convenience init(internalSerialQueueName: String, serialQueueConfiguration: ((DispatchQueue) -> Void)? = nil, leeway: DispatchTimeInterval = DispatchTimeInterval.nanoseconds(0))
Parameters
internalSerialQueueName
Name of internal serial dispatch queue.
serialQueueConfiguration
Additional configuration of internal serial dispatch queue.
leeway
The amount of time, in nanoseconds, that the system will defer the timer.
-
Constructs new
SerialDispatchQueueScheduler
namedinternalSerialQueueName
that wrapsqueue
.Declaration
Swift
public convenience init(queue: DispatchQueue, internalSerialQueueName: String, leeway: DispatchTimeInterval = DispatchTimeInterval.nanoseconds(0))
Parameters
queue
Possibly concurrent dispatch queue used to perform work.
internalSerialQueueName
Name of internal serial dispatch queue proxy.
leeway
The amount of time, in nanoseconds, that the system will defer the timer.
-
Constructs new
SerialDispatchQueueScheduler
that wraps one of the global concurrent dispatch queues.Declaration
Swift
@available(macOS 10.10, *) public convenience init(qos: DispatchQoS, internalSerialQueueName: String = "rx.global_dispatch_queue.serial", leeway: DispatchTimeInterval = DispatchTimeInterval.nanoseconds(0))
Parameters
qos
Identifier for global dispatch queue with specified quality of service class.
internalSerialQueueName
Custom name for internal serial dispatch queue proxy.
leeway
The amount of time, in nanoseconds, that the system will defer the timer.
-
Schedules an action to be executed immediately.
Declaration
Swift
public final func schedule<StateType>(_ state: StateType, action: @escaping (StateType) -> Disposable) -> Disposable
Parameters
state
State passed to the action to be executed.
action
Action to be executed.
Return Value
The disposable object used to cancel the scheduled action (best effort).
-
Schedules an action to be executed.
Declaration
Swift
public final func scheduleRelative<StateType>(_ state: StateType, dueTime: RxTimeInterval, action: @escaping (StateType) -> Disposable) -> Disposable
Parameters
state
State passed to the action to be executed.
dueTime
Relative time after which to execute the action.
action
Action to be executed.
Return Value
The disposable object used to cancel the scheduled action (best effort).
-
Schedules a periodic piece of work.
Declaration
Swift
public func schedulePeriodic<StateType>(_ state: StateType, startAfter: RxTimeInterval, period: RxTimeInterval, action: @escaping (StateType) -> StateType) -> Disposable
Parameters
state
State passed to the action to be executed.
startAfter
Period after which initial work should be run.
period
Period for running the work periodically.
action
Action to be executed.
Return Value
The disposable object used to cancel the scheduled action (best effort).