Skip to content

Commit

Permalink
Merge pull request #249 from djtarazona/feature/when-void-promises-ar…
Browse files Browse the repository at this point in the history
…ray-swift-2.0

Allow an array of void promises for `when` (Swift 2.0)
  • Loading branch information
nathanhosselton committed Aug 28, 2015
2 parents 31a1869 + a2718b2 commit 0881d5c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/when.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation.NSProgress

private func when<T>(promises: [Promise<T>]) -> Promise<Void> {
private func _when<T>(promises: [Promise<T>]) -> Promise<Void> {
let (rootPromise, fulfill, reject) = Promise<Void>.pendingPromise()
#if !PMKDisableProgress
let progress = NSProgress(totalUnitCount: Int64(promises.count))
Expand Down Expand Up @@ -63,21 +63,25 @@ private func when<T>(promises: [Promise<T>]) -> Promise<Void> {
- SeeAlso: `join()`
*/
public func when<T>(promises: [Promise<T>]) -> Promise<[T]> {
return when(promises).then(on: zalgo) { promises.map{ $0.value! } }
return _when(promises).then(on: zalgo) { promises.map{ $0.value! } }
}

public func when<T>(promises: Promise<T>...) -> Promise<[T]> {
return when(promises)
}

public func when(promises: Promise<Void>...) -> Promise<Void> {
return when(promises)
return _when(promises)
}

public func when(promises: [Promise<Void>]) -> Promise<Void> {
return _when(promises)
}

public func when<U, V>(pu: Promise<U>, _ pv: Promise<V>) -> Promise<(U, V)> {
return when(pu.asVoid(), pv.asVoid()).then(on: zalgo) { (pu.value!, pv.value!) }
return _when([pu.asVoid(), pv.asVoid()]).then(on: zalgo) { (pu.value!, pv.value!) }
}

public func when<U, V, X>(pu: Promise<U>, _ pv: Promise<V>, _ px: Promise<X>) -> Promise<(U, V, X)> {
return when(pu.asVoid(), pv.asVoid(), px.asVoid()).then(on: zalgo) { (pu.value!, pv.value!, px.value!) }
return _when([pu.asVoid(), pv.asVoid(), px.asVoid()]).then(on: zalgo) { (pu.value!, pv.value!, px.value!) }
}

0 comments on commit 0881d5c

Please sign in to comment.