Created
May 8, 2020 08:37
-
-
Save creaaa/fc688ff314d106f2634ae120d9d55bc2 to your computer and use it in GitHub Desktop.
This file contains 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
func testFuture() { | |
let expectation1 = XCTestExpectation(description: self.debugDescription) | |
var cancellables = Set<AnyCancellable>() | |
let future = Future<Int, Error> { promise in | |
promise(.success(42)) | |
} | |
// Future自体は他のPubと全く同じように、Subされて初めて値を放出し始めるのだから、 | |
// Deferred なんていらないのでは? | |
DispatchQueue.global().asyncAfter(deadline: .now() + 3) { | |
future | |
.assertNoFailure() | |
.sink( | |
receiveCompletion: { fini in | |
print(fini) | |
}, | |
receiveValue: { print($0) } | |
) | |
.store(in: &cancellables) | |
} | |
wait(for: [expectation1], timeout: 10.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment