Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 895e932

Browse files
committed
added Promises.wait
1 parent 15f10d2 commit 895e932

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Promises.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Promises'
3-
s.version = '1.0.0'
3+
s.version = '1.0.1'
44
s.summary = 'I promise the future!'
55
s.description = <<-DESC
66
It's just another Promise library that works on

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pod 'Promises'
1313

1414
### SPM
1515
```
16-
.package(url: "https://github.com/CoreKit/Promises.git", from: "1.0.0"),
16+
.package(url: "https://github.com/CoreKit/Promises.git", from: "1.0.1"),
1717
```
1818

1919
### Carthage
2020
```
21-
github "CoreKit/Promises" "1.0.0"
21+
github "CoreKit/Promises" "1.0.1"
2222
```
2323

2424
## Pod cheatsheet

Sources/Promises.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,24 @@ public enum Promises {
352352
}
353353
}
354354
}
355-
355+
356+
@discardableResult
357+
public static func wait<T>(_ promises: [Promise<T>]) -> Promise<Void> {
358+
return Promise<Void> { fulfill, _ in
359+
guard !promises.isEmpty else {
360+
return fulfill(())
361+
}
362+
let complete: ((Any) -> Void) = { _ in
363+
if !promises.contains(where: { $0.isPending }) {
364+
fulfill(())
365+
}
366+
}
367+
for promise in promises {
368+
promise.then(success: complete, failure: complete)
369+
}
370+
}
371+
}
372+
356373
@discardableResult
357374
public static func race<T>(_ promises: [Promise<T>]) -> Promise<T> {
358375
return Promise<T> { fulfill, reject in

0 commit comments

Comments
 (0)