Skip to content

Commit 80e871e

Browse files
Merge branch 'ReneB-master'
2 parents 8db942b + 97fa4e4 commit 80e871e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

Sources/Promise+Properties.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ extension Promise {
1313
}
1414
}
1515

16+
/**
17+
Provides an alias for the `error` property for cases where the Swift
18+
compiler cannot disambiguate from our `error` function.
19+
20+
More than likely use of this alias will never be necessary as it's
21+
the inverse situation where Swift usually becomes confused. But
22+
we provide this anyway just in case.
23+
24+
If you absolutely cannot get Swift to accept `error` then
25+
`errorValue` may be used instead as it returns the same thing.
26+
27+
- Warning: This alias will be unavailable in PromiseKit 4.0.0
28+
- SeeAlso: [https://github.com/mxcl/PromiseKit/issues/347](https://github.com/mxcl/PromiseKit/issues/347)
29+
*/
30+
@available(*, deprecated, renamed="error", message="Temporary alias `errorValue` will eventually be removed and should only be used when the Swift compiler cannot be satisfied with `error`")
31+
public var errorValue: ErrorType? {
32+
return self.error
33+
}
34+
1635
/**
1736
- Returns: `true` if the promise has not yet resolved.
1837
*/

Sources/Promise.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,33 @@ public class Promise<T> {
390390
}
391391
}
392392

393+
/**
394+
Provides an alias for the `error` function for cases where the Swift
395+
compiler cannot disambiguate from our `error` property. If you're
396+
having trouble with `error`, before using this alias, first try
397+
being as explicit as possible with the types e.g.:
398+
399+
}.error { (error:ErrorType) -> Void in
400+
//...
401+
}
402+
403+
Or even using verbose function syntax:
404+
405+
}.error({ (error:ErrorType) -> Void in
406+
//...
407+
})
408+
409+
If you absolutely cannot get Swift to accept `error` then `onError`
410+
may be used instead as it does the same thing.
411+
412+
- Warning: This alias will be unavailable in PromiseKit 4.0.0
413+
- SeeAlso: [https://github.com/mxcl/PromiseKit/issues/347](https://github.com/mxcl/PromiseKit/issues/347)
414+
*/
415+
@available(*, deprecated, renamed="error", message="Temporary alias `onError` will eventually be removed and should only be used when the Swift compiler cannot be satisfied with `error`")
416+
public func onError(policy policy: ErrorPolicy = .AllErrorsExceptCancellation, _ body: (ErrorType) -> Void) {
417+
error(policy: policy, body)
418+
}
419+
393420
/**
394421
The provided closure is executed when this promise is rejected giving you
395422
an opportunity to recover from the error and continue the promise chain.

Tests/CorePromise/ErrorUnhandler.test.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ class ErrorHandlingTests_Swift: XCTestCase {
116116
}
117117
}
118118

119+
// a temporary alias `onError` exists for the `error` function
120+
func test7() {
121+
twice { promise, ex in
122+
PMKUnhandledErrorHandler = { err in
123+
XCTFail()
124+
}
125+
126+
promise.onError { error in
127+
ex.fulfill()
128+
}
129+
}
130+
}
131+
119132
func testDoubleRejectDoesNotTriggerUnhandler() {
120133
enum Error: ErrorType {
121134
case Test

0 commit comments

Comments
 (0)