Skip to content

Commit

Permalink
Avoid last request after cancellation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizmb authored Jan 26, 2022
1 parent 737b543 commit 45cfd7d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/CombineLongPolling/LongPollingPublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ extension LongPollingPublisher {
// on the first run, the semaphore is 1, so we are not blocked here and fetch the data immediately.
semaphore.wait()

lock.lock()
guard started && !finished else {
lock.unlock()
return
}
lock.unlock()

currentRequest = dataTaskPublisher
.catch { error -> AnyPublisher<(data: Data, response: URLResponse), URLError> in
// Timeout errors are accepted as valid. In Long Polling terms that means that there's no output during the
Expand Down

0 comments on commit 45cfd7d

Please sign in to comment.