Add a variadic method for emit completion handlers in swift
This commit is contained in:
parent
d763fad449
commit
b3e305fd14
@ -221,6 +221,18 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
|
||||
handleClientEvent(.error, data: [event, items, error])
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an event to the server, with optional data items and write completion handler.
|
||||
///
|
||||
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
|
||||
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
|
||||
///
|
||||
/// - parameter event: The event to send.
|
||||
/// - parameter items: The items to send with this event. May be left out.
|
||||
/// - parameter completion: Callback called on transport write completion.
|
||||
open func emit(_ event: String, _ items: SocketData..., completion: @escaping () -> ()) {
|
||||
emit([event] + items, completion: completion)
|
||||
}
|
||||
|
||||
/// Same as emit, but meant for Objective-C
|
||||
///
|
||||
|
||||
@ -101,6 +101,16 @@ public protocol SocketIOClientSpec : AnyObject {
|
||||
/// - parameter items: The items to send with this event. May be left out.
|
||||
func emit(_ event: String, _ items: SocketData...)
|
||||
|
||||
/// Send an event to the server, with optional data items and write completion handler.
|
||||
///
|
||||
/// If an error occurs trying to transform `items` into their socket representation, a `SocketClientEvent.error`
|
||||
/// will be emitted. The structure of the error data is `[eventName, items, theError]`
|
||||
///
|
||||
/// - parameter event: The event to send.
|
||||
/// - parameter items: The items to send with this event. May be left out.
|
||||
/// - parameter completion: Callback called on transport write completion.
|
||||
func emit(_ event: String, _ items: SocketData..., completion: @escaping () -> ())
|
||||
|
||||
/// Call when you wish to tell the server that you've received the event for `ack`.
|
||||
///
|
||||
/// - parameter ack: The ack number.
|
||||
|
||||
@ -27,6 +27,11 @@ class SocketSideEffectTest: XCTestCase {
|
||||
XCTAssertEqual(socket.currentAck, 1)
|
||||
}
|
||||
|
||||
func testEmitCompletionSyntax() {
|
||||
socket.emit("test", completion: {})
|
||||
socket.emit("test", "thing", completion: {})
|
||||
}
|
||||
|
||||
func testHandleAck() {
|
||||
let expect = expectation(description: "handled ack")
|
||||
socket.emitWithAck("test").timingOut(after: 0) {data in
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user