             
             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() {

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

                    return
                }
                
                getConnectionInfo { connectionInfo in
                    guard let connectionInfo = connectionInfo 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)
                }
            }
        }
        
