I can not find a solution to my problem: It is necessary to wait for the answer from the closure in the function, tell me how to do it? Here is the code:
import Foundation import RMQClient import SwiftyJSON func getMessage() -> [String:Any] { var answer: [String:Any] = [:] let conn = RMQConnection(uri: "amqp://\(self.login):\(self.password)@\(self.ip1):\(self.port1)", delegate: RMQConnectionDelegateLogger()) conn.start() let ch = conn.createChannel() let q = ch.queue("client_" + String(self.phoneNumber), options: .autoDelete) ch.queueBind("client_" + String(self.phoneNumber), exchange: "sysPay", routingKey: String(self.phoneNumber)) q.subscribe({(_ message: RMQMessage) -> Void in print("Received \(String(data: message.body, encoding: .utf8))") let json = try? JSON(message.body) answer["type"] = message.messageType() for (key, value) in (json?.dictionary)! { answer[key] = value } if answer.count <= 0 { answer["type"] = "no_connect" } }) return answer }
return always works before receiving a response from the circuit! And here q.subscribe({(_ message: RMQMessage) -> Void
result can only be void.
Tell me how to wait for the result from the closure and then return the result from the function? Thank.