add no timeout

This commit is contained in:
Erik 2015-03-14 19:46:03 -04:00
parent d75457f397
commit 2022f282c9
3 changed files with 15 additions and 10 deletions

View File

@ -103,7 +103,8 @@ socket.on("ackEvent") {data, ack in
println("Got int") println("Got int")
} }
socket.emitWithAck("ackTest", "test").onAck {data in // You can specify a custom timeout interval. 0 means no timeout.
socket.emitWithAck("ackTest", "test").onAck(0) {data in
println(data?[0]) println(data?[0])
} }

View File

@ -40,6 +40,8 @@ public typealias AckCallback = (NSArray?) -> Void
public func onAck(timeout:UInt64, withCallback callback:AckCallback) { public func onAck(timeout:UInt64, withCallback callback:AckCallback) {
self.callback = callback self.callback = callback
if timeout != 0 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC)) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
if self == nil { if self == nil {
@ -51,6 +53,7 @@ public typealias AckCallback = (NSArray?) -> Void
} }
} }
} }
}
func executeAck(data:NSArray?) { func executeAck(data:NSArray?) {
dispatch_async(dispatch_get_main_queue()) {[weak self, cb = self.callback] in dispatch_async(dispatch_get_main_queue()) {[weak self, cb = self.callback] in

View File

@ -396,6 +396,7 @@ public class SocketIOClient: NSObject {
if self.reconnectTimer == nil { if self.reconnectTimer == nil {
self._reconnecting = true self._reconnecting = true
dispatch_async(dispatch_get_main_queue()) {[weak self] in dispatch_async(dispatch_get_main_queue()) {[weak self] in
if self == nil { if self == nil {
return return