You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wrapping my network requests into signals like this:
func request<Response>(_ endpoint: Endpoint<Response>) -> Signal<Response, ResponseError> {
return Signal<Response, ResponseError> { observer in
let request = self.manager.request(
self.url(path: endpoint.path),
method: httpMethod(from: endpoint.method),
parameters: endpoint.parameters,
encoding: endpoint.encoding
)
request
.validate()
.responseData() { response in
let result = response.result.flatMap(endpoint.decode)
switch result {
case .success(let value):
observer.next(value)
observer.completed()
case .failure(let error):
observer.failed(ResponseError(reason: error.localizedDescription,
statusCode: response.response?.statusCode ?? 0))
}
}
return BlockDisposable {
request.cancel()
}
}
}
The issue I am having is that when I am observing this signal, the callback is triggered twice .next with value and .completed. I don't want it to be called twice because obviously I am executing code to update the UI inside the callback.
Sometimes the value is null (for some requests I expect 200 with empty response), so I cannot check the value.
If I don't call .completed after .next, the issue disappears but I not sure if it would cause a memory issue because the signal is being disposed in the case of a .failed or .completed event as seen here:
public func on(_ event: Event<Element, Error>) {
lock.lock(); defer { lock.unlock() }
guard !disposable.isDisposed else { return }
if let observer = observer {
observer(event)
if event.isTerminal {
disposable.dispose()
}
}
}
Any suggestions?
The text was updated successfully, but these errors were encountered:
I am wrapping my network requests into signals like this:
The issue I am having is that when I am observing this signal, the callback is triggered twice .next with value and .completed. I don't want it to be called twice because obviously I am executing code to update the UI inside the callback.
Sometimes the value is null (for some requests I expect 200 with empty response), so I cannot check the value.
If I don't call .completed after .next, the issue disappears but I not sure if it would cause a memory issue because the signal is being disposed in the case of a .failed or .completed event as seen here:
Any suggestions?
The text was updated successfully, but these errors were encountered: