Skip to content

Commit

Permalink
Rename runOnEventLoop(channel:task:)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nethra Ravindran committed Aug 30, 2018
1 parent 27e1158 commit d9ba6e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,25 @@ public class ClientRequest {

// Make the HTTP request, the response callbacks will be received on the HTTPClientHandler.
// We are mostly not running on the event loop. Let's make sure we send the request over the event loop.
runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
self.sendRequest(request: request, on: self.channel)
}
waitSemaphore.wait()

// We are now free to close the connection if asked for.
if closeConnection {
runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
self.channel.close(promise: nil)
}
}
}

/// Executes task on event loop
private func runOnEventLoop(channel: Channel, _ task: @escaping () -> Void) {
if channel.eventLoop.inEventLoop {
private func execute(on eventLoop: EventLoop, _ task: @escaping () -> Void) {
if eventLoop.inEventLoop {
task()
} else {
channel.eventLoop.execute {
eventLoop.execute {
task()
}
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/KituraNet/HTTP/HTTPServerResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class HTTPServerResponse: ServerResponse {
}

if buffer == nil {
runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
self.buffer = channel.allocator.buffer(capacity: string.utf8.count)
self.buffer!.write(string: string)
}
Expand All @@ -88,19 +88,19 @@ public class HTTPServerResponse: ServerResponse {
}

if buffer == nil {
runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
self.buffer = channel.allocator.buffer(capacity: data.count)
self.buffer!.write(bytes: data)
}
}
}

/// Executes task on event loop
private func runOnEventLoop(channel: Channel, _ task: @escaping () -> Void) {
if channel.eventLoop.inEventLoop {
private func execute(on eventLoop: EventLoop, _ task: @escaping () -> Void) {
if eventLoop.inEventLoop {
task()
} else {
channel.eventLoop.execute {
eventLoop.execute {
task()
}
}
Expand All @@ -121,7 +121,7 @@ public class HTTPServerResponse: ServerResponse {
fatalError("No channel available.")
}

runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
do {
try self.end0(channel: channel)
} catch let error {
Expand Down Expand Up @@ -163,7 +163,7 @@ public class HTTPServerResponse: ServerResponse {
fatalError("No channel available.")
}

runOnEventLoop(channel: channel) {
execute(on: channel.eventLoop) {
do {
try self.end0(with: errorCode, channel: channel, withBody: withBody)
} catch let error {
Expand Down

0 comments on commit d9ba6e1

Please sign in to comment.