ValueObservationScheduler

public class ValueObservationScheduler

ValueObservationScheduler determines how ValueObservation notifies its fresh values.

  • A scheduler which asynchronously notifies fresh value of the given DispatchQueue.

    For example:

    let observation = ValueObservation.tracking { db in
        try Player.fetchAll(db)
    }
    
    let cancellable = try observation.start(
        in: dbQueue,
        scheduling: .async(onQueue: .main),
        onError: { error in ... },
        onChange: { players: [Player] in
            print("fresh players: \(players)")
        })
    

    Declaration

    Swift

    public static func async(onQueue queue: DispatchQueue) -> ValueObservationScheduler
  • A scheduler which notifies all values on the main queue. The first one is immediately notified when the start() method is called.

    For example:

    let observation = ValueObservation.tracking { db in
        try Player.fetchAll(db)
    }
    
    let cancellable = try observation.start(
        in: dbQueue,
        scheduling: .immediate,
        onError: { error in ... },
        onChange: { players: [Player] in
            print("fresh players: \(players)")
        })
    // <- here "fresh players" is already printed.
    

    Important

    this scheduler requires that the observation is started from the main queue. A fatal error is raised otherwise.

    Declaration

    Swift

    public static let immediate: ValueObservationScheduler