Functions

The following functions are available globally.

  • Waits on an array of Promises and returns a Promise that is fulfilled with an array of the resulting fulfilled values.

    The value of the returned Promise is an array of the same length as the input array and where each element in the resulting array corresponds to the same element in the input array.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the returned Promise behaves.

    Declaration

    Swift

    public func when<Value, Error>(fulfilled promises: [Promise<Value, Error>], qos: DispatchQoS.QoSClass = .default, cancelOnFailure: Bool = false) -> Promise<[Value], Error>

    Parameters

    promises

    An array of Promises whose fulfilled values will be collected to fulfill the returned Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Waits on a tuple of Promises and returns a Promise that is fulfilled with a tuple of the resulting values.

    The value of the returned Promise is an tuple where each element in the resulting tuple corresponds to the same element in the input tuple.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the resulting Promise behaves.

    Declaration

    Swift

    public func when<Value1,Value2,Value3,Value4,Value5,Value6,Error>(fulfilled a: Promise<Value1,Error>,
                                                                      _ b: Promise<Value2,Error>,
                                                                      _ c: Promise<Value3,Error>,
                                                                      _ d: Promise<Value4,Error>,
                                                                      _ e: Promise<Value5,Error>,
                                                                      _ f: Promise<Value6,Error>,
                                                                      qos: DispatchQoS.QoSClass = .default,
                                                                      cancelOnFailure: Bool = false)
        -> Promise<(Value1,Value2,Value3,Value4,Value5,Value6),Error>

    Parameters

    a

    A Promise whose value is included in the resulting Promise.

    b

    A Promise whose value is included in the resulting Promise.

    c

    A Promise whose value is included in the resulting Promise.

    d

    A Promise whose value is included in the resulting Promise.

    e

    A Promise whose value is included in the resulting Promise.

    f

    A Promise whose value is included in the resulting Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Waits on a tuple of Promises and returns a Promise that is fulfilled with a tuple of the resulting values.

    The value of the returned Promise is an tuple where each element in the resulting tuple corresponds to the same element in the input tuple.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the resulting Promise behaves.

    Declaration

    Swift

    public func when<Value1,Value2,Value3,Value4,Value5,Error>(fulfilled a: Promise<Value1,Error>,
                                                               _ b: Promise<Value2,Error>,
                                                               _ c: Promise<Value3,Error>,
                                                               _ d: Promise<Value4,Error>,
                                                               _ e: Promise<Value5,Error>,
                                                               qos: DispatchQoS.QoSClass = .default,
                                                               cancelOnFailure: Bool = false)
        -> Promise<(Value1,Value2,Value3,Value4,Value5),Error>

    Parameters

    a

    A Promise whose value is included in the resulting Promise.

    b

    A Promise whose value is included in the resulting Promise.

    c

    A Promise whose value is included in the resulting Promise.

    d

    A Promise whose value is included in the resulting Promise.

    e

    A Promise whose value is included in the resulting Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Waits on a tuple of Promises and returns a Promise that is fulfilled with a tuple of the resulting values.

    The value of the returned Promise is an tuple where each element in the resulting tuple corresponds to the same element in the input tuple.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the resulting Promise behaves.

    Declaration

    Swift

    public func when<Value1,Value2,Value3,Value4,Error>(fulfilled a: Promise<Value1,Error>,
                                                        _ b: Promise<Value2,Error>,
                                                        _ c: Promise<Value3,Error>,
                                                        _ d: Promise<Value4,Error>,
                                                        qos: DispatchQoS.QoSClass = .default,
                                                        cancelOnFailure: Bool = false)
        -> Promise<(Value1,Value2,Value3,Value4),Error>

    Parameters

    a

    A Promise whose value is included in the resulting Promise.

    b

    A Promise whose value is included in the resulting Promise.

    c

    A Promise whose value is included in the resulting Promise.

    d

    A Promise whose value is included in the resulting Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Waits on a tuple of Promises and returns a Promise that is fulfilled with a tuple of the resulting values.

    The value of the returned Promise is an tuple where each element in the resulting tuple corresponds to the same element in the input tuple.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the resulting Promise behaves.

    Declaration

    Swift

    public func when<Value1,Value2,Value3,Error>(fulfilled a: Promise<Value1,Error>,
                                                 _ b: Promise<Value2,Error>,
                                                 _ c: Promise<Value3,Error>,
                                                 qos: DispatchQoS.QoSClass = .default,
                                                 cancelOnFailure: Bool = false)
        -> Promise<(Value1,Value2,Value3),Error>

    Parameters

    a

    A Promise whose value is included in the resulting Promise.

    b

    A Promise whose value is included in the resulting Promise.

    c

    A Promise whose value is included in the resulting Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Waits on a tuple of Promises and returns a Promise that is fulfilled with a tuple of the resulting values.

    The value of the returned Promise is an tuple where each element in the resulting tuple corresponds to the same element in the input tuple.

    If any input Promise is rejected, the resulting Promise is rejected with the same error. If any input Promise is cancelled, the resulting Promise is cancelled. If multiple input Promises are rejected or cancelled, the first such one determines how the resulting Promise behaves.

    Declaration

    Swift

    public func when<Value1,Value2,Error>(fulfilled a: Promise<Value1,Error>,
                                          _ b: Promise<Value2,Error>,
                                          qos: DispatchQoS.QoSClass = .default,
                                          cancelOnFailure: Bool = false)
        -> Promise<(Value1,Value2),Error>

    Parameters

    a

    A Promise whose value is included in the resulting Promise.

    b

    A Promise whose value is included in the resulting Promise.

    qos

    The QoS to use for the dispatch queues that coordinate the work. The default value is .default.

    cancelOnFailure

    If true, all input Promises will be cancelled if any of them are rejected or cancelled. The default value of false means rejecting or cancelling an input Promise does not cancel the rest.

    Return Value

    A Promise that will be fulfilled with an array of the fulfilled values from each input Promise.

  • Returns a Promise that is resolved with the result of the first resolved input Promise.

    The first input Promise that is either fulfilled or rejected causes the resulting Promise to be fulfilled or rejected. An input Promise that is cancelled is ignored. If all input Promises are cancelled, the resulting Promise is cancelled.

    Declaration

    Swift

    public func when<Value, Error>(first promises: [Promise<Value, Error>], cancelRemaining: Bool = false) -> Promise<Value, Error>

    Parameters

    promises

    An array of Promises.

    cancelRemaining

    If true, all remaining input Promises will be cancelled as soon as the first one is resolved. The default value of false means resolving an input Promise does not cancel the rest.

    Return Value

    A Promise that will be resolved with the value or error from the first fulfilled or rejected input Promise.