dispatch events on main queue

This commit is contained in:
Erik 2015-02-15 18:51:43 -05:00
parent 5d8479ed36
commit 44de79d8c5

View File

@ -248,23 +248,25 @@ class SocketIOClient: NSObject, SRWebSocketDelegate {
func handleEvent(event:String, data:AnyObject?, isInternalMessage:Bool = false,
wantsAck ack:Int? = nil, withAckType ackType:Int = 3) {
// println("Should do event: \(event) with data: \(data)")
if !self.connected && !isInternalMessage {
return
}
for handler in self.handlers {
if handler.event == event {
if data is NSArray {
handler.executeCallback(nil, items: (data as! NSArray))
if ack != nil {
self.emitAck(ack!, withEvent: event,
withData: handler.ack.ackData, withAckType: ackType)
}
} else {
handler.executeCallback(data)
if ack != nil {
self.emitAck(ack!, withEvent: event,
withData: handler.ack.ackData, withAckType: ackType)
dispatch_async(dispatch_get_main_queue()) {
if !self.connected && !isInternalMessage {
return
}
for handler in self.handlers {
if handler.event == event {
if data is NSArray {
handler.executeCallback(nil, items: (data as! NSArray))
if ack != nil {
self.emitAck(ack!, withEvent: event,
withData: handler.ack.ackData, withAckType: ackType)
}
} else {
handler.executeCallback(data)
if ack != nil {
self.emitAck(ack!, withEvent: event,
withData: handler.ack.ackData, withAckType: ackType)
}
}
}
}