MainScheduler

public final class MainScheduler : SerialDispatchQueueScheduler

Abstracts work that needs to be performed on DispatchQueue.main. In case schedule methods are called from DispatchQueue.main, it will perform action immediately without scheduling.

This scheduler is usually used to perform UI work.

Main scheduler is a specialization of SerialDispatchQueueScheduler.

This scheduler is optimized for observeOn operator. To ensure observable sequence is subscribed on main thread using subscribeOn operator please use ConcurrentMainScheduler because it is more optimized for that purpose.

  • Initializes new instance of MainScheduler.

    Declaration

    Swift

    public init()
  • Singleton instance of MainScheduler

    Declaration

    Swift

    public static let instance: MainScheduler
  • Singleton instance of MainScheduler that always schedules work asynchronously and doesn’t perform optimizations for calls scheduled from main queue.

    Declaration

    Swift

    public static let asyncInstance: SerialDispatchQueueScheduler
  • In case this method is called on a background thread it will throw an exception.

    Declaration

    Swift

    public class func ensureExecutingOnScheduler(errorMessage: String? = nil)