-
Notifications
You must be signed in to change notification settings - Fork 721
Move Isolated EL operations to EL protocol #3070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,7 @@ public struct NIOIsolatedEventLoop { | |
| @available(*, noasync) | ||
| @inlinable | ||
| public func execute(_ task: @escaping () -> Void) { | ||
| let unsafeTransfer = UnsafeTransfer(task) | ||
| self._wrapped.execute { | ||
| unsafeTransfer.wrappedValue() | ||
| } | ||
| self._wrapped._executeIsolatedUnsafeUnchecked(task) | ||
| } | ||
|
|
||
| /// Submit a given task to be executed by the `EventLoop`. Once the execution is complete the returned `EventLoopFuture` is notified. | ||
|
|
@@ -48,10 +45,7 @@ public struct NIOIsolatedEventLoop { | |
| @available(*, noasync) | ||
| @inlinable | ||
| public func submit<T>(_ task: @escaping () throws -> T) -> EventLoopFuture<T> { | ||
| let unsafeTransfer = UnsafeTransfer(task) | ||
| return self._wrapped.submit { | ||
| try unsafeTransfer.wrappedValue() | ||
| } | ||
| self._wrapped._submitIsolatedUnsafeUnchecked(task) | ||
| } | ||
|
|
||
| /// Schedule a `task` that is executed by this `EventLoop` at the given time. | ||
|
|
@@ -70,10 +64,7 @@ public struct NIOIsolatedEventLoop { | |
| deadline: NIODeadline, | ||
| _ task: @escaping () throws -> T | ||
| ) -> Scheduled<T> { | ||
| let unsafeTransfer = UnsafeTransfer(task) | ||
| return self._wrapped.scheduleTask(deadline: deadline) { | ||
| try unsafeTransfer.wrappedValue() | ||
| } | ||
| self._wrapped._scheduleTaskIsolatedUnsafeUnchecked(deadline: deadline, task) | ||
| } | ||
|
|
||
| /// Schedule a `task` that is executed by this `EventLoop` after the given amount of time. | ||
|
|
@@ -93,10 +84,7 @@ public struct NIOIsolatedEventLoop { | |
| in delay: TimeAmount, | ||
| _ task: @escaping () throws -> T | ||
| ) -> Scheduled<T> { | ||
| let unsafeTransfer = UnsafeTransfer(task) | ||
| return self._wrapped.scheduleTask(in: delay) { | ||
| try unsafeTransfer.wrappedValue() | ||
| } | ||
| self._wrapped._scheduleTaskIsolatedUnsafeUnchecked(in: delay, task) | ||
| } | ||
|
|
||
| /// Schedule a `task` that is executed by this `EventLoop` at the given time. | ||
|
|
@@ -122,10 +110,11 @@ public struct NIOIsolatedEventLoop { | |
| line: UInt = #line, | ||
| _ task: @escaping () throws -> EventLoopFuture<T> | ||
| ) -> Scheduled<T> { | ||
| let unsafeTransfer = UnsafeTransfer(task) | ||
| return self._wrapped.flatScheduleTask(deadline: deadline, file: file, line: line) { | ||
| try unsafeTransfer.wrappedValue() | ||
| } | ||
| let promise: EventLoopPromise<T> = self._wrapped.makePromise(file: file, line: line) | ||
| let scheduled = self.scheduleTask(deadline: deadline, task) | ||
|
|
||
| scheduled.futureResult.flatMap { $0 }.cascade(to: promise) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we save an alloc here if we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so: the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean like this (I appreciate it's more code than the scheduled.futureResult.whenComplete { result in
switch result {
case .success(let futureResult):
promise.completeWith(futureResult)
case .failure(let error):
promise.fail(error)
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're probably right. However, all the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for filing that, makes sense to track them together. |
||
| return .init(promise: promise, cancellationTask: { scheduled.cancel() }) | ||
| } | ||
|
|
||
| /// Returns the wrapped event loop. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.