I have a swift command line application which uses socket.io to communicate with a server. The issue is that the library that I use is asynchronous and as such once the application is done connecting and enters the loop, the event handlers in the main thread are never executed.
I understand I need to use some form of GDC, but most example on here only deal with synchronous processing after an asynchronous call. But what I want to do, is just leave the main thread free to handle events from workers.
Here is a naive approach that leaves the main thread unable to process handlers:
import Foundation
let socket = SocketIOClient(socketURL: "localhost:3000", options: [.Log(true), .ForceWebsockets(true)])
socket.on("connect") {data, ack in
print("socket connected")
}
socket.on("config") {data, ack in
print("got my config")
}
socket.connect()
while (true){
sleep(1)
}
Now, how would I go about making a runloop, or using GDC to make it possible for the handlers to be executed?