From 6ca554f4ad7f87d40791ce5f7bde061897f7bc4e Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 20 May 2017 16:52:24 -0400 Subject: [PATCH] Use guard statements in polling --- Source/SocketEnginePollable.swift | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Source/SocketEnginePollable.swift b/Source/SocketEnginePollable.swift index 699553e..3c73927 100644 --- a/Source/SocketEnginePollable.swift +++ b/Source/SocketEnginePollable.swift @@ -114,9 +114,7 @@ extension SocketEnginePollable { /// /// You shouldn't need to call this directly, the engine should automatically maintain a long-poll request. public func doPoll() { - if websocket || waitingForPoll || !connected || closed { - return - } + guard !websocket && !waitingForPoll && connected && !closed else { return } var req = URLRequest(url: urlPollingWithSid) addHeaders(to: &req) @@ -125,9 +123,7 @@ extension SocketEnginePollable { } func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> Void) { - if !polling || closed || invalidated || fastUpgrade { - return - } + guard polling && !closed && !invalidated && !fastUpgrade else { return } DefaultSocketLogger.Logger.log("Doing polling %@ %@", type: "SocketEnginePolling", args: req.httpMethod ?? "", req) @@ -168,10 +164,10 @@ extension SocketEnginePollable { } private func flushWaitingForPost() { - if postWait.count == 0 || !connected { - return - } else if websocket { + guard postWait.count != 0 && connected else { return } + guard !websocket else { flushWaitingForPostToWebSocket() + return }