Last active
June 17, 2016 12:25
-
-
Save oleksii-demedetskyi/7a9777531f33046839f4337ce85e7985 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Future { | |
func then<U>(f: T -> Future<U>) -> Future<U> { | |
let promise = Promise<U>() | |
self.onFail { promise.fail() }.onSuccess { | |
f($0).onFail { promise.fail() }.onSuccess { promise.resolve($0) } | |
} | |
return promise.future | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment