Skip to content

Commit 2022f28

Browse files
committed
add no timeout
1 parent d75457f commit 2022f28

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ socket.on("ackEvent") {data, ack in
103103
println("Got int")
104104
}
105105

106-
socket.emitWithAck("ackTest", "test").onAck {data in
106+
// You can specify a custom timeout interval. 0 means no timeout.
107+
socket.emitWithAck("ackTest", "test").onAck(0) {data in
107108
println(data?[0])
108109
}
109110

SwiftIO/SocketAckHandler.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ public typealias AckCallback = (NSArray?) -> Void
4040
public func onAck(timeout:UInt64, withCallback callback:AckCallback) {
4141
self.callback = callback
4242

43-
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
44-
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
45-
if self == nil {
46-
return
47-
}
48-
49-
if !self!.acked {
50-
self?.executeAck(["No ACK"])
43+
44+
if timeout != 0 {
45+
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(timeout * NSEC_PER_SEC))
46+
dispatch_after(time, dispatch_get_main_queue()) {[weak self] in
47+
if self == nil {
48+
return
49+
}
50+
51+
if !self!.acked {
52+
self?.executeAck(["No ACK"])
53+
}
5154
}
5255
}
5356
}

SwiftIO/SocketIOClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class SocketIOClient: NSObject {
5050

5151
internal var currentAck = -1
5252
internal var waitingData = [SocketEvent]()
53-
53+
5454
public var closed:Bool {
5555
return self._closed
5656
}
@@ -396,6 +396,7 @@ public class SocketIOClient: NSObject {
396396

397397
if self.reconnectTimer == nil {
398398
self._reconnecting = true
399+
399400
dispatch_async(dispatch_get_main_queue()) {[weak self] in
400401
if self == nil {
401402
return

0 commit comments

Comments
 (0)