             
             semaphore.wait()
             
-            if let result = result {
-                return result
-            }
-            else {
-                Thread.sleep(forTimeInterval: 10)
-                return getConnectionInfo()
-            }
+            
+            guard let realResult = result else {
+                DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + 10) {
+                    getConnectionInfo(completion: completion)
+                }
+                return
+            }
+            
+            completion(realResult)
         }
         
         private static func startUpdating() {

                    return
                }
                
                guard let connectionInfo = getConnectionInfo() else {
                    VK.Log.put("LongPoll", "Fail to get connection info")
                    return
                }
                
                VK.Log.put("LongPoll", "Start updating")
                
                let updateOperation = LongPollUpdatingOperation(
                    server: connectionInfo.server,
                    lpKey: connectionInfo.lpKey,
                    startTs: connectionInfo.ts,
                    onResponse: { updates in
                        parse(updates)
                    },
                    onKeyExpired: {
                        updateQueue.cancelAllOperations()
                        startUpdating()
                    }
                )
            
                updateQueue.addOperation(updateOperation)
            }
        }
        

        }
        
        // swiftlint:disable:next large_tuple
        private static func getConnectionInfo(completion: @escaping ((server: String, lpKey: String, ts: String)?) -> ()) {
            guard isActive, VK.state == .authorized else {
                VK.Log.put("LongPoll", "User is not authorized")
                completion(nil)
                return
            }
            
            let semaphore = DispatchSemaphore(value: 0)
