             request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
         }
     }
+
+    private func markTransportClosed() -> Bool {
+        var previousCloseStatus = false
+
+        transportQueue.sync {
+            previousCloseStatus = isTransportClosed
+            isTransportClosed = true
+        }
+
+        return previousCloseStatus
+    }
 }
 
 fileprivate enum WebSocketsTransportError: Error {

        }

        webSocket!.event.close = { code, reason, clean in
            if clean {
                self.delegate?.transportDidClose(nil)
            } else {

import Foundation

public class WebsocketsTransport: Transport {
    private let transportQueue: DispatchQueue = DispatchQueue(label: "SignalR.webSocketTransport.queue")
    private var isTransportClosed = false

    var webSocket:WebSocket? = nil
    public weak var delegate: TransportDelegate? = nil

