I'm now developing a redis client for swift. I tried to use asynchronous callback delegate to handle to result sent from the redis server using:
func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent)
But every time I will open a new connection with the server and after a command is executed, the connection will be closed which is not efficient. I looked up how Jedis implement this and figured out Jedis is using its inputstream's 'read' function which is a synchronous call - it will block the process until the last command's result is received. My question is, how can I do this using Apple's NSStream? One idea is to poll request after sending a command, but is there a more graceful way to do this?