Permalink
Browse files

change newPromise(for: T.Type) to newPromise(of: T.Type) (#672)

Motivation:

making a promise of a type is more grammatical than making a promise for
a type.

Modifications:

s/newPromise(for/newPromise(of/g

Result:

more grammar
  • Loading branch information...
weissi authored and Lukasa committed Nov 28, 2018
1 parent c1a84a0 commit a20e129c22ad00a51c902dca54a5456f90664780
@@ -347,7 +347,7 @@ public func swiftMain() -> Int {
struct MyError: Error { }
@inline(never)
func doThenAndFriends(loop: EventLoop) {
let p = loop.newPromise(for: Int.self)
let p = loop.newPromise(of: Int.self)
let f = p.futureResult.then { (r: Int) -> EventLoopFuture<Int> in
// This call allocates a new Future, and
// so does then(), so this is two Futures.
@@ -384,9 +384,9 @@ public func swiftMain() -> Int {
}
@inline(never)
func doAnd(loop: EventLoop) {
let p1 = loop.newPromise(for: Int.self)
let p2 = loop.newPromise(for: Int.self)
let p3 = loop.newPromise(for: Int.self)
let p1 = loop.newPromise(of: Int.self)
let p2 = loop.newPromise(of: Int.self)
let p3 = loop.newPromise(of: Int.self)
// Each call to and() allocates a Future. The calls to
// and(result:) allocate two.
@@ -468,7 +468,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
public final func setOption<T: ChannelOption>(option: T, value: T.OptionType) -> EventLoopFuture<Void> {
if eventLoop.inEventLoop {
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
executeAndComplete(promise) { try setOption0(option: option, value: value) }
return promise.futureResult
} else {
@@ -797,7 +797,7 @@ class BaseSocketChannel<T: BaseSocket>: SelectableChannel, ChannelCore {
self.eventLoop.assertInEventLoop()
assert(self.isOpen)
assert(!self.lifecycleManager.isActive)
let registerPromise = self.eventLoop.newPromise(for: Void.self)
let registerPromise = self.eventLoop.newPromise(of: Void.self)
self.register0(promise: registerPromise)
registerPromise.futureResult.whenFailure { (_: Error) in
self.close(promise: nil)
@@ -189,7 +189,7 @@ public extension BlockingIOThreadPool {
/// - body: The closure which performs some blocking work to be done on the thread pool.
/// - returns: The `EventLoopFuture` of `promise` fulfilled with the result (or error) of the passed closure.
func runIfActive<T>(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture<T> {
let promise = eventLoop.newPromise(for: T.self)
let promise = eventLoop.newPromise(of: T.self)
self.submit { shouldRun in
guard case shouldRun = BlockingIOThreadPool.WorkItemState.active else {
promise.fail(error: ChannelError.ioOnClosedChannel)
@@ -172,7 +172,7 @@ public final class ServerBootstrap {
return try ServerSocketChannel(descriptor: descriptor, eventLoop: eventLoop, group: childEventLoopGroup)
}
return bind0(makeServerChannel: makeChannel) { (eventLoop, serverChannel) in
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
serverChannel.registerAlreadyConfigured0(promise: promise)
return promise.futureResult
}
@@ -433,7 +433,7 @@ public final class ClientBootstrap {
/// - returns: An `EventLoopFuture<Channel>` to deliver the `Channel` when connected.
public func connect(to address: SocketAddress) -> EventLoopFuture<Channel> {
return execute(eventLoop: group.next(), protocolFamily: address.protocolFamily) { channel in
let connectPromise = channel.eventLoop.newPromise(for: Void.self)
let connectPromise = channel.eventLoop.newPromise(of: Void.self)
channel.connect(to: address, promise: connectPromise)
let cancelTask = channel.eventLoop.scheduleTask(in: self.connectTimeout) {
connectPromise.fail(error: ChannelError.connectTimeout(self.connectTimeout))
@@ -479,7 +479,7 @@ public final class ClientBootstrap {
return channelInitializer(channel).then {
self.channelOptions.applyAll(channel: channel)
}.then {
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
channel.registerAlreadyConfigured0(promise: promise)
return promise.futureResult
}.map {
@@ -496,7 +496,7 @@ public final class ClientBootstrap {
let channelInitializer = self.channelInitializer ?? { _ in eventLoop.newSucceededFuture(result: ()) }
let channelOptions = self.channelOptions
let promise = eventLoop.newPromise(for: Channel.self)
let promise = eventLoop.newPromise(of: Channel.self)
let channel: SocketChannel
do {
channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: protocolFamily)
@@ -595,7 +595,7 @@ public final class DatagramBootstrap {
return try DatagramChannel(eventLoop: eventLoop, descriptor: descriptor)
}
return bind0(makeChannel: makeChannel) { (eventLoop, channel) in
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
channel.registerAlreadyConfigured0(promise: promise)
return promise.futureResult
}
@@ -717,7 +717,7 @@ public final class DatagramBootstrap {
}
func applyAll(channel: Channel) -> EventLoopFuture<Void> {
let applyPromise = channel.eventLoop.newPromise(for: Void.self)
let applyPromise = channel.eventLoop.newPromise(of: Void.self)
var it = self.storage.makeIterator()
func applyNext() {
@@ -163,7 +163,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - first: `true` to add this handler to the front of the `ChannelPipeline`, `false to add it last
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was added.
public func add(name: String? = nil, handler: ChannelHandler, first: Bool = false) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
func _add() {
if self.destroyed {
@@ -199,7 +199,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - after: The pre-existing `ChannelHandler` that `handler` should be inserted immediately after.
/// - returns: An `EventLoopFuture` that will be notified when the `ChannelHandler` is added.
public func add(name: String? = nil, handler: ChannelHandler, after: ChannelHandler) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
if self.eventLoop.inEventLoop {
self.add0(name: name, handler: handler, relativeHandler: after, operation: self.add0(context:after:), promise: promise)
@@ -222,7 +222,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - after: The pre-existing `ChannelHandler` that `handler` should be inserted immediately before.
/// - returns: An `EventLoopFuture` that will be notified when the `ChannelHandler` is added.
public func add(name: String? = nil, handler: ChannelHandler, before: ChannelHandler) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
if self.eventLoop.inEventLoop {
self.add0(name: name, handler: handler, relativeHandler: before, operation: self.add0(context:before:), promise: promise)
@@ -356,7 +356,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - handler: the `ChannelHandler` to remove.
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
public func remove(handler: ChannelHandler) -> EventLoopFuture<Bool> {
let promise = self.eventLoop.newPromise(for: Bool.self)
let promise = self.eventLoop.newPromise(of: Bool.self)
self.remove(handler: handler, promise: promise)
return promise.futureResult
}
@@ -367,7 +367,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - name: the name that was used to add the `ChannelHandler` to the `ChannelPipeline` before.
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
public func remove(name: String) -> EventLoopFuture<Bool> {
let promise = self.eventLoop.newPromise(for: Bool.self)
let promise = self.eventLoop.newPromise(of: Bool.self)
self.remove(name: name, promise: promise)
return promise.futureResult
}
@@ -378,7 +378,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// - ctx: the `ChannelHandlerContext` that belongs to `ChannelHandler` that should be removed.
/// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed.
public func remove(ctx: ChannelHandlerContext) -> EventLoopFuture<Bool> {
let promise = self.eventLoop.newPromise(for: Bool.self)
let promise = self.eventLoop.newPromise(of: Bool.self)
self.remove(ctx: ctx, promise: promise)
return promise.futureResult
}
@@ -464,7 +464,7 @@ public final class ChannelPipeline: ChannelInvoker {
/// Find a `ChannelHandlerContext` in the `ChannelPipeline`.
private func context0(_ body: @escaping ((ChannelHandlerContext) -> Bool)) -> EventLoopFuture<ChannelHandlerContext> {
let promise = eventLoop.newPromise(for: ChannelHandlerContext.self)
let promise = eventLoop.newPromise(of: ChannelHandlerContext.self)
func _context0() {
if let ctx = self.contextForPredicate0(body) {
@@ -318,7 +318,7 @@ extension EventLoop {
}
/// Creates and returns a new `EventLoopPromise` that will be notified using this `EventLoop` as execution `Thread`.
public func newPromise<T>(for type: T.Type = T.self, file: StaticString = #file, line: UInt = #line) -> EventLoopPromise<T> {
public func newPromise<T>(of type: T.Type = T.self, file: StaticString = #file, line: UInt = #line) -> EventLoopPromise<T> {
return EventLoopPromise<T>(eventLoop: self, file: file, line: line)
}
@@ -757,7 +757,7 @@ internal final class SelectableEventLoop: EventLoop {
if self.inEventLoop {
return closeGently0()
} else {
let p = self.newPromise(for: Void.self)
let p = self.newPromise(of: Void.self)
self.execute {
closeGently0().cascade(promise: p)
}
@@ -123,7 +123,7 @@ private struct CallbackList: ExpressibleByArrayLiteral {
///
/// ```
/// func someAsyncOperation(args) -> EventLoopFuture<ResultType> {
/// let promise = eventLoop.newPromise(for: ResultType.self)
/// let promise = eventLoop.newPromise(of: ResultType.self)
/// someAsyncOperationWithACallback(args) { result -> Void in
/// // when finished...
/// promise.succeed(result: result)
@@ -218,7 +218,7 @@ public struct EventLoopPromise<T> {
///
/// ```
/// func getNetworkData(args) -> EventLoopFuture<NetworkResponse> {
/// let promise = eventLoop.newPromise(for: NetworkResponse.self)
/// let promise = eventLoop.newPromise(of: NetworkResponse.self)
/// queue.async {
/// . . . do some work . . .
/// promise.succeed(response)
@@ -928,7 +928,7 @@ extension EventLoopFuture {
/// - updateAccumulatingResult: The bifunction used to combine partialResults with new elements.
/// - returns: A new `EventLoopFuture` with the combined value.
public static func reduce<U>(into initialResult: T, _ futures: [EventLoopFuture<U>], eventLoop: EventLoop, _ updateAccumulatingResult: @escaping (inout T, U) -> Void) -> EventLoopFuture<T> {
let p0 = eventLoop.newPromise(for: T.self)
let p0 = eventLoop.newPromise(of: T.self)
var result: T = initialResult
let f0 = eventLoop.newSucceededFuture(result: ())
@@ -967,7 +967,7 @@ public extension EventLoopFuture {
// We're already on that event loop, nothing to do here. Save an allocation.
return self
}
let hoppingPromise = target.newPromise(for: T.self)
let hoppingPromise = target.newPromise(of: T.self)
self.cascade(promise: hoppingPromise)
return hoppingPromise.futureResult
}
@@ -62,13 +62,13 @@ public extension MulticastChannel {
}
func joinGroup(_ group: SocketAddress) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
self.joinGroup(group, promise: promise)
return promise.futureResult
}
func joinGroup(_ group: SocketAddress, interface: NIONetworkInterface?) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
self.joinGroup(group, interface: interface, promise: promise)
return promise.futureResult
}
@@ -78,13 +78,13 @@ public extension MulticastChannel {
}
func leaveGroup(_ group: SocketAddress) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
self.leaveGroup(group, promise: promise)
return promise.futureResult
}
func leaveGroup(_ group: SocketAddress, interface: NIONetworkInterface?) -> EventLoopFuture<Void> {
let promise = self.eventLoop.newPromise(for: Void.self)
let promise = self.eventLoop.newPromise(of: Void.self)
self.leaveGroup(group, interface: interface, promise: promise)
return promise.futureResult
}
@@ -381,7 +381,7 @@ final class ServerSocketChannel: BaseSocketChannel<ServerSocket> {
return
}
let p = eventLoop.newPromise(for: Void.self)
let p = eventLoop.newPromise(of: Void.self)
p.futureResult.map {
// It's important to call the methods before we actually notify the original promise for ordering reasons.
self.becomeActive0(promise: promise)
@@ -213,7 +213,7 @@ public extension SocketOptionProvider {
extension BaseSocketChannel: SocketOptionProvider {
public func unsafeSetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName, value: Value) -> EventLoopFuture<Void> {
if eventLoop.inEventLoop {
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
executeAndComplete(promise) {
try setSocketOption0(level: level, name: name, value: value)
}
@@ -227,7 +227,7 @@ extension BaseSocketChannel: SocketOptionProvider {
public func unsafeGetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName) -> EventLoopFuture<Value> {
if eventLoop.inEventLoop {
let promise = eventLoop.newPromise(for: Value.self)
let promise = eventLoop.newPromise(of: Value.self)
executeAndComplete(promise) {
try getSocketOption0(level: level, name: name)
}
@@ -342,7 +342,7 @@ private final class HTTPHandler: ChannelInboundHandler {
}
return ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buffer))))
}.then { () -> EventLoopFuture<Void> in
let p = ctx.eventLoop.newPromise(for: Void.self)
let p = ctx.eventLoop.newPromise(of: Void.self)
self.completeResponse(ctx, trailers: nil, promise: p)
return p.futureResult
}.thenIfError { error in
@@ -364,7 +364,7 @@ private final class HTTPHandler: ChannelInboundHandler {
let response = responseHead(request: request, fileRegion: region)
ctx.write(self.wrapOutboundOut(.head(response)), promise: nil)
ctx.writeAndFlush(self.wrapOutboundOut(.body(.fileRegion(region)))).then {
let p = ctx.eventLoop.newPromise(for: Void.self)
let p = ctx.eventLoop.newPromise(of: Void.self)
self.completeResponse(ctx, trailers: nil, promise: p)
return p.futureResult
}.thenIfError { (_: Error) in
@@ -27,7 +27,7 @@ private class PromiseOrderer {
}
func newPromise() -> EventLoopPromise<Void> {
let promise = eventLoop.newPromise(for: Void.self)
let promise = eventLoop.newPromise(of: Void.self)
appendPromise(promise)
return promise
}
@@ -501,7 +501,7 @@ class HTTPResponseCompressorTest: XCTestCase {
let channel = try compressionChannel()
try sendRequest(acceptEncoding: "gzip", channel: channel)
let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok)
let writePromise = channel.eventLoop.newPromise(for: Void.self)
let writePromise = channel.eventLoop.newPromise(of: Void.self)
channel.write(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise)
writePromise.futureResult.map {
XCTFail("Write succeeded")
@@ -528,7 +528,7 @@ class HTTPResponseCompressorTest: XCTestCase {
let channel = try compressionChannel()
try sendRequest(acceptEncoding: nil, channel: channel)
let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok)
let writePromise = channel.eventLoop.newPromise(for: Void.self)
let writePromise = channel.eventLoop.newPromise(of: Void.self)
channel.writeAndFlush(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise)
channel.pipeline.removeHandlers()
try writePromise.futureResult.wait()
Oops, something went wrong.

0 comments on commit a20e129

Please sign in to comment.