Skip to content

Commit

Permalink
Ensure the completion: callback is always invoked, regardless of th…
Browse files Browse the repository at this point in the history
…e scenario
  • Loading branch information
jguz-pubnub committed Jan 22, 2025
1 parent 51163d6 commit d84eb7d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/PubNub/Networking/Request/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ final class Request {

deinit {
PubNub.log.debug("Request Destroyed \(requestID)")


let currentState = atomicState.lockedRead { $0 }
let taskState = currentState.taskState

// Ensure that the response is always delivered to the caller. This situation could occur if the task is created
// but not yet resumed, and the session is invalidated in the meantime.
if taskState == .initialized {
let error = PubNubError(.clientCancelled)
atomicState.lockedWrite { $0.error = error }
finish(error: error)
}

atomicState.lockedWrite { $0.purgeAll() }
}

Expand Down

0 comments on commit d84eb7d

Please sign in to comment.