Skip to content

Instantly share code, notes, and snippets.

@creaaa
Created May 8, 2020 08:37
Show Gist options
  • Save creaaa/fc688ff314d106f2634ae120d9d55bc2 to your computer and use it in GitHub Desktop.
Save creaaa/fc688ff314d106f2634ae120d9d55bc2 to your computer and use it in GitHub Desktop.
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