Skip to content

Commit

Permalink
Changed EventLoop{Future,Promise}<()> occurances to EventLoop{Future,…
Browse files Browse the repository at this point in the history
…Promise}<Void> (#211) (#219)

Motivation:

Fix inconsistency of <Void> and <()> occurances in the codebase.

Modifications:

Changed EventLoop{Future,Promise}<()> occurances to EventLoop{Future,Promise}<Void>

Result:

Consistent code style for EventLoopPromise and EventLoopFuture.
  • Loading branch information
tib authored and normanmaurer committed Mar 22, 2018
1 parent 5362983 commit 1f83a1d
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 97 deletions.
22 changes: 11 additions & 11 deletions Sources/NIO/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public final class ServerBootstrap {

private let group: EventLoopGroup
private let childGroup: EventLoopGroup
private var serverChannelInit: ((Channel) -> EventLoopFuture<()>)?
private var childChannelInit: ((Channel) -> EventLoopFuture<()>)?
private var serverChannelInit: ((Channel) -> EventLoopFuture<Void>)?
private var childChannelInit: ((Channel) -> EventLoopFuture<Void>)?
private var serverChannelOptions = ChannelOptionStorage()
private var childChannelOptions = ChannelOptionStorage()

Expand Down Expand Up @@ -87,7 +87,7 @@ public final class ServerBootstrap {
///
/// - parameters:
/// - initializer: A closure that initializes the provided `Channel`.
public func serverChannelInitializer(_ initializer: @escaping (Channel) -> EventLoopFuture<()>) -> Self {
public func serverChannelInitializer(_ initializer: @escaping (Channel) -> EventLoopFuture<Void>) -> Self {
self.serverChannelInit = initializer
return self
}
Expand All @@ -99,7 +99,7 @@ public final class ServerBootstrap {
///
/// - parameters:
/// - initializer: A closure that initializes the provided `Channel`.
public func childChannelInitializer(_ initializer: @escaping (Channel) -> EventLoopFuture<()>) -> Self {
public func childChannelInitializer(_ initializer: @escaping (Channel) -> EventLoopFuture<Void>) -> Self {
self.childChannelInit = initializer
return self
}
Expand Down Expand Up @@ -199,10 +199,10 @@ public final class ServerBootstrap {
private class AcceptHandler: ChannelInboundHandler {
public typealias InboundIn = SocketChannel

private let childChannelInit: ((Channel) -> EventLoopFuture<()>)?
private let childChannelInit: ((Channel) -> EventLoopFuture<Void>)?
private let childChannelOptions: ChannelOptionStorage

init(childChannelInitializer: ((Channel) -> EventLoopFuture<()>)?, childChannelOptions: ChannelOptionStorage) {
init(childChannelInitializer: ((Channel) -> EventLoopFuture<Void>)?, childChannelOptions: ChannelOptionStorage) {
self.childChannelInit = childChannelInitializer
self.childChannelOptions = childChannelOptions
}
Expand All @@ -214,7 +214,7 @@ public final class ServerBootstrap {
self.childChannelOptions.applyAll(channel: accepted).hopTo(eventLoop: ctx.eventLoop).then {
assert(ctx.eventLoop.inEventLoop)
return childChannelInit(accepted)
}.then { () -> EventLoopFuture<()> in
}.then { () -> EventLoopFuture<Void> in
assert(ctx.eventLoop.inEventLoop)
guard !ctx.pipeline.destroyed else {
return accepted.close().thenThrowing {
Expand Down Expand Up @@ -268,7 +268,7 @@ public final class ServerBootstrap {
public final class ClientBootstrap {

private let group: EventLoopGroup
private var channelInitializer: ((Channel) -> EventLoopFuture<()>)?
private var channelInitializer: ((Channel) -> EventLoopFuture<Void>)?
private var channelOptions = ChannelOptionStorage()
private var connectTimeout: TimeAmount = TimeAmount.seconds(10)
private var resolver: Resolver?
Expand All @@ -288,7 +288,7 @@ public final class ClientBootstrap {
///
/// - parameters:
/// - handler: A closure that initializes the provided `Channel`.
public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<()>) -> Self {
public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<Void>) -> Self {
self.channelInitializer = handler
return self
}
Expand Down Expand Up @@ -427,7 +427,7 @@ public final class ClientBootstrap {
public final class DatagramBootstrap {

private let group: EventLoopGroup
private var channelInitializer: ((Channel) -> EventLoopFuture<()>)?
private var channelInitializer: ((Channel) -> EventLoopFuture<Void>)?
private var channelOptions = ChannelOptionStorage()

/// Create a `DatagramBootstrap` on the `EventLoopGroup` `group`.
Expand All @@ -443,7 +443,7 @@ public final class DatagramBootstrap {
///
/// - parameters:
/// - handler: A closure that initializes the provided `Channel`.
public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<()>) -> Self {
public func channelInitializer(_ handler: @escaping (Channel) -> EventLoopFuture<Void>) -> Self {
self.channelInitializer = handler
return self
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/DeadChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal final class DeadChannel: Channel {
let eventLoop: EventLoop
let pipeline: ChannelPipeline

public var closeFuture: EventLoopFuture<()> {
public var closeFuture: EventLoopFuture<Void> {
return self.eventLoop.newSucceededFuture(result: ())
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/NIO/NonBlockingFileIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct NonBlockingFileIO {
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
allocator: ByteBufferAllocator,
eventLoop: EventLoop,
chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<()>) -> EventLoopFuture<()> {
chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
do {
let readableBytes = fileRegion.readableBytes
try fileRegion.fileHandle.withUnsafeFileDescriptor { descriptor in
Expand Down Expand Up @@ -115,17 +115,17 @@ public struct NonBlockingFileIO {
byteCount: Int,
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
allocator: ByteBufferAllocator,
eventLoop: EventLoop, chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<()>) -> EventLoopFuture<()> {
eventLoop: EventLoop, chunkHandler: @escaping (ByteBuffer) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
precondition(chunkSize > 0, "chunkSize must be > 0 (is \(chunkSize))")
var remainingReads = 1 + (byteCount / chunkSize)
let lastReadSize = byteCount % chunkSize

func _read(remainingReads: Int) -> EventLoopFuture<()> {
func _read(remainingReads: Int) -> EventLoopFuture<Void> {
if remainingReads > 1 || (remainingReads == 1 && lastReadSize > 0) {
let readSize = remainingReads > 1 ? chunkSize : lastReadSize
assert(readSize > 0)
return self.read(fileHandle: fileHandle, byteCount: readSize, allocator: allocator, eventLoop: eventLoop).then { buffer in
chunkHandler(buffer).then { () -> EventLoopFuture<()> in
chunkHandler(buffer).then { () -> EventLoopFuture<Void> in
assert(eventLoop.inEventLoop)
return _read(remainingReads: remainingReads - 1)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIO/PendingWritesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private struct PendingStreamWritesState {
///
/// - returns: The `EventLoopPromise` of the write or `nil` if none was provided. The promise needs to be fulfilled by the caller.
///
private mutating func fullyWrittenFirst() -> EventLoopPromise<()>? {
private mutating func fullyWrittenFirst() -> EventLoopPromise<Void>? {
self.chunks -= 1
let first = self.pendingWrites.removeFirst()
self.subtractOutstanding(bytes: first.data.readableBytes)
Expand Down Expand Up @@ -184,7 +184,7 @@ private struct PendingStreamWritesState {
/// - writeResult: The result of the write operation.
/// - returns: A closure that the caller _needs_ to run which will fulfill the promises of the writes and a `OneWriteOperationResult` which indicates if we could write everything or not.
public mutating func didWrite(itemCount: Int, result writeResult: IOResult<Int>) -> (() -> Void, OneWriteOperationResult) {
var promises: [EventLoopPromise<()>] = []
var promises: [EventLoopPromise<Void>] = []
let fulfillPromises = { promises.forEach { $0.succeed(result: ()) } }

switch writeResult {
Expand Down Expand Up @@ -225,7 +225,7 @@ private struct PendingStreamWritesState {
///
/// - returns: A closure that the caller _needs_ to run which will fulfill the promises.
public mutating func failAll(error: Error) -> (() -> Void) {
var promises: [EventLoopPromise<()>] = []
var promises: [EventLoopPromise<Void>] = []
promises.reserveCapacity(self.pendingWrites.count)
while !self.pendingWrites.isEmpty {
if let p = self.fullyWrittenFirst() {
Expand Down
4 changes: 2 additions & 2 deletions Sources/NIOHTTP1/HTTPEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import NIO

private func writeChunk(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHandlerContext, isChunked: Bool, chunk: IOData, promise: EventLoopPromise<Void>?) {
let (mW1, mW2, mW3): (EventLoopPromise<()>?, EventLoopPromise<()>?, EventLoopPromise<()>?)
let (mW1, mW2, mW3): (EventLoopPromise<Void>?, EventLoopPromise<Void>?, EventLoopPromise<Void>?)

switch (isChunked, promise) {
case (true, .some(let p)):
/* chunked encoding and the user's interested: we need three promises and need to cascade into the users promise */
let (w1, w2, w3) = (ctx.eventLoop.newPromise() as EventLoopPromise<()>, ctx.eventLoop.newPromise() as EventLoopPromise<()>, ctx.eventLoop.newPromise() as EventLoopPromise<()>)
let (w1, w2, w3) = (ctx.eventLoop.newPromise() as EventLoopPromise<Void>, ctx.eventLoop.newPromise() as EventLoopPromise<Void>, ctx.eventLoop.newPromise() as EventLoopPromise<Void>)
w1.futureResult.and(w2.futureResult).and(w3.futureResult).map { (_: ((((), ()), ()))) in }.cascade(promise: p)
(mW1, mW2, mW3) = (w1, w2, w3)
case (false, .some(let p)):
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOHTTP1Server/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private final class HTTPHandler: ChannelInboundHandler {
private var continuousCount: Int = 0

private var handler: ((ChannelHandlerContext, HTTPServerRequestPart) -> Void)?
private var handlerFuture: EventLoopFuture<()>?
private var handlerFuture: EventLoopFuture<Void>?
private let fileIO: NonBlockingFileIO

public init(fileIO: NonBlockingFileIO, htdocsPath: String) {
Expand Down
10 changes: 5 additions & 5 deletions Tests/NIOHTTP1Tests/HTTPTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HTTPTest: XCTestCase {
return s
}

func sendAndCheckRequests(_ expecteds: [HTTPRequestHead], body: String?, trailers: HTTPHeaders?, sendStrategy: (String, EmbeddedChannel) -> EventLoopFuture<()>) throws -> String? {
func sendAndCheckRequests(_ expecteds: [HTTPRequestHead], body: String?, trailers: HTTPHeaders?, sendStrategy: (String, EmbeddedChannel) -> EventLoopFuture<Void>) throws -> String? {
var step = 0
var index = 0
let channel = EmbeddedChannel()
Expand Down Expand Up @@ -103,7 +103,7 @@ class HTTPTest: XCTestCase {
return reqPart
}).wait()

var writeFutures: [EventLoopFuture<()>] = []
var writeFutures: [EventLoopFuture<Void>] = []
for expected in expecteds {
writeFutures.append(sendStrategy(httpRequestStrForRequest(expected), channel))
index += 1
Expand All @@ -113,7 +113,7 @@ class HTTPTest: XCTestCase {
bodyData = nil
}
channel.pipeline.flush()
XCTAssertNoThrow(try EventLoopFuture<()>.andAll(writeFutures, eventLoop: channel.eventLoop).wait())
XCTAssertNoThrow(try EventLoopFuture<Void>.andAll(writeFutures, eventLoop: channel.eventLoop).wait())
XCTAssertEqual(2 * expecteds.count, step)

if body != nil {
Expand All @@ -140,7 +140,7 @@ class HTTPTest: XCTestCase {

/* send the bytes one by one */
let bd2 = try sendAndCheckRequests(expecteds, body: body, trailers: trailers, sendStrategy: { (reqString, chan) in
var writeFutures: [EventLoopFuture<()>] = []
var writeFutures: [EventLoopFuture<Void>] = []
for c in reqString {
var buf = chan.allocator.buffer(capacity: 1024)

Expand All @@ -149,7 +149,7 @@ class HTTPTest: XCTestCase {
try chan.writeInbound(buf)
})
}
return EventLoopFuture<()>.andAll(writeFutures, eventLoop: chan.eventLoop)
return EventLoopFuture<Void>.andAll(writeFutures, eventLoop: chan.eventLoop)
})

XCTAssertEqual(bd1, bd2)
Expand Down
Loading

0 comments on commit 1f83a1d

Please # to comment.