Skip to content

Commit

Permalink
Merge pull request #54 from noppoMan/escaping-closure
Browse files Browse the repository at this point in the history
make completion closures @escaping
  • Loading branch information
noppoMan authored Aug 11, 2016
2 parents cdfd18c + 6d9dd14 commit 6b6683f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Sources/AsyncConnection.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
public protocol AsyncConnection: AsyncStream {
func open(timingOut deadline: Double, completion: ((Void) throws -> AsyncConnection) -> Void) throws
func open(timingOut deadline: Double, completion: @escaping ((Void) throws -> AsyncConnection) -> Void) throws
}

extension AsyncConnection {
public func open(completion: ((Void) throws -> AsyncConnection) -> Void) throws {
public func open(completion: @escaping ((Void) throws -> AsyncConnection) -> Void) throws {
try open(timingOut: .never, completion: completion)
}
}
7 changes: 4 additions & 3 deletions Sources/AsyncDrain.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public final class AsyncDrain: DataRepresentable, AsyncStream {

var buffer: Data = []
public var closed = false

Expand Down Expand Up @@ -58,7 +59,7 @@ public final class AsyncDrain: DataRepresentable, AsyncStream {
closed = true
}

public func receive(upTo byteCount: Int, timingOut deadline: Double = .never, completion: ((Void) throws -> Data) -> Void) {
public func receive(upTo byteCount: Int, timingOut deadline: Double = .never, completion: @escaping ((Void) throws -> Data) -> Void) {
if byteCount >= buffer.count {
completion { [unowned self] in
try self.close()
Expand All @@ -75,12 +76,12 @@ public final class AsyncDrain: DataRepresentable, AsyncStream {
}
}

public func send(_ data: Data, timingOut deadline: Double = .never, completion: ((Void) throws -> Void) -> Void) {
public func send(_ data: Data, timingOut deadline: Double = .never, completion: @escaping ((Void) throws -> Void) -> Void) {
buffer += data.bytes
completion {}
}

public func flush(timingOut deadline: Double = .never, completion: ((Void) throws -> Void) -> Void) {
public func flush(timingOut deadline: Double = .never, completion: @escaping ((Void) throws -> Void) -> Void) {
buffer = []
completion {}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/AsyncHost.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
public protocol AsyncHost {
func accept(timingOut deadline: Double, completion: ((Void) throws -> AsyncStream) -> Void)
func accept(timingOut deadline: Double, completion: @escaping ((Void) throws -> AsyncStream) -> Void)
}

extension AsyncHost {
public func accept(completion: ((Void) throws -> AsyncStream) -> Void) {
public func accept(completion: @escaping ((Void) throws -> AsyncStream) -> Void) {
accept(timingOut: .never, completion: completion)
}
}
12 changes: 6 additions & 6 deletions Sources/AsyncStream.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
public protocol AsyncSending {
func send(_ data: Data, timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void)
func flush(timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void)
func send(_ data: Data, timingOut deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void)
func flush(timingOut deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void)
}

public protocol AsyncReceiving {
func receive(upTo byteCount: Int, timingOut deadline: Double, completion: ((Void) throws -> Data) -> Void)
func receive(upTo byteCount: Int, timingOut deadline: Double, completion: @escaping ((Void) throws -> Data) -> Void)
}

public protocol AsyncSendingStream: Closable, AsyncSending {}
public protocol AsyncReceivingStream: Closable, AsyncReceiving {}
public protocol AsyncStream: AsyncSendingStream, AsyncReceivingStream {}

extension AsyncSending {
public func send(_ data: Data, completion: ((Void) throws -> Void) -> Void) {
public func send(_ data: Data, completion: @escaping ((Void) throws -> Void) -> Void) {
send(data, timingOut: .never, completion: completion)
}
public func flush(completion: ((Void) throws -> Void) -> Void) {
public func flush(completion: @escaping ((Void) throws -> Void) -> Void) {
flush(timingOut: .never, completion: completion)
}
}

extension AsyncReceiving {
public func receive(upTo byteCount: Int, completion: ((Void) throws -> Data) -> Void) {
public func receive(upTo byteCount: Int, completion: @escaping ((Void) throws -> Data) -> Void) {
receive(upTo: byteCount, timingOut: .never, completion: completion)
}
}
8 changes: 4 additions & 4 deletions Sources/Stream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public protocol ReceivingStream: Closable, Receiving {}
public protocol Stream: SendingStream, ReceivingStream {}

extension Sending {
public func send(_ data: Data, timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) {
public func send(_ data: Data, timingOut deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) {
completion { try self.send(data, timingOut: deadline) }
}

public func flush(timingOut deadline: Double, completion: ((Void) throws -> Void) -> Void) {
public func flush(timingOut deadline: Double, completion: @escaping ((Void) throws -> Void) -> Void) {
completion { try self.flush(timingOut: deadline) }
}
}
Expand All @@ -32,7 +32,7 @@ extension Sending {
}

extension Receiving {
public func receive(upTo byteCount: Int, timingOut deadline: Double, completion: ((Void) throws -> Data) -> Void) {
public func receive(upTo byteCount: Int, timingOut deadline: Double, completion: @escaping ((Void) throws -> Data) -> Void) {
completion { try self.receive(upTo: byteCount, timingOut: deadline) }
}
}
Expand All @@ -41,4 +41,4 @@ extension Receiving {
public func receive(upTo byteCount: Int) throws -> Data {
return try receive(upTo: byteCount, timingOut: .never)
}
}
}

0 comments on commit 6b6683f

Please sign in to comment.