Sink not printing any values
simplisafevish opened this issue · comments
Sink not working here, neither breakpoint nor printing users.
func testNetworkAPI() {
let service = MyApi()
let request = UserRequest()
let response = request.schedule(with: service)
_ = response.sink(receiveCompletion: { completion in
switch completion {
case .failure(let error):
print("Request failed due to: \(error)")
case .finished:
print("Request finished.")
}
}) { users in
print("Received users: \(users)")
}
}
This is most likely not an issue of the library: you ignore the return value (the cancellable) and as soon as the cancellable's reference count is set to 0, the request is aborted. Since you never have a reference, the request is aborted without even being started. Make sure you assign the cancellable to some variable where the reference remains for the duration of the request.
Thank you, its worked after using cancellable variable.