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")
}
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])
}

View File

@ -40,14 +40,17 @@ public typealias AckCallback = (NSArray?) -> Void
public func onAck(timeout:UInt64, withCallback callback:AckCallback) {
self.callback = callback
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
if self == nil {
return
}
if !self!.acked {
self?.executeAck(["No ACK"])
if timeout != 0 {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
if self == nil {
return
}
if !self!.acked {
self?.executeAck(["No ACK"])
}
}
}
}

View File

@ -50,7 +50,7 @@ public class SocketIOClient: NSObject {
internal var currentAck = -1
internal var waitingData = [SocketEvent]()
public var closed:Bool {
return self._closed
}
@ -396,6 +396,7 @@ public class SocketIOClient: NSObject {
if self.reconnectTimer == nil {
self._reconnecting = true
dispatch_async(dispatch_get_main_queue()) {[weak self] in
if self == nil {
return