PromiseContext

public enum PromiseContext : Equatable, Hashable

The context in which a Promise body or callback is evaluated.

Most of these values correspond with Dispatch QoS classes.

  • Execute on the main queue.

    Note

    Chained callbacks on the .main context guarantee that they all execute within the same run loop pass. This means UI manipulations in chained callbacks on .main will all occur within the same CoreAnimation transaction. The only exception is if a callback returns an unresolved nested promise, as the subsequent callbacks must wait for that promise to resolve first.

    Declaration

    Swift

    case main
  • Execute on a dispatch queue with the .background QoS.

    Declaration

    Swift

    case background
  • Execute on a dispatch queue with the .utility QoS.

    Declaration

    Swift

    case utility
  • Execute on a dispatch queue with the .default QoS.

    Declaration

    Swift

    case `default`
  • Execute on a dispatch queue with the .userInitiated QoS.

    Declaration

    Swift

    case userInitiated
  • Execute on a dispatch queue with the .userInteractive QoS.

    Declaration

    Swift

    case userInteractive
  • Execute on the specified dispatch queue.

    Declaration

    Swift

    case queue(DispatchQueue)
  • Execute on the specified operation queue.

    Declaration

    Swift

    case operationQueue(OperationQueue)
  • Execute synchronously.

    Important

    If you use this option with a callback you must be prepared to handle the callback executing on any thread. This option is usually only used when creating a promise, and with callbacks is generally only suitable for running short bits of code that are thread-independent. For example you may want to use this with resolver.onRequestCancel if all you’re doing is cancelling the promise, or asking a network task to cancel, e.g.

    resolver.onRequestCancel(on: .immediate, { (_) in task.cancel() })

    Declaration

    Swift

    case immediate
  • Returns .main when accessed from the main thread, otherwise .default.

    Declaration

    Swift

    public static var auto: PromiseContext { get }
  • Returns the PromiseContext that corresponds to a given Dispatch QoS class.

    If the given QoS is .unspecified then .default is assumed.

    Declaration

    Swift

    public init(qos: DispatchQoS.QoSClass)
  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    public static func == (lhs: PromiseContext, rhs: PromiseContext) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.