Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d20621

Browse files
committedFeb 19, 2024·
George review
1 parent e0a87fc commit 5d20621

File tree

2 files changed

+14
-61
lines changed

2 files changed

+14
-61
lines changed
 

‎Sources/NIOCore/EventLoop.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ extension EventLoop {
736736
/// - returns: An `EventLoopFuture` identical to the `EventLoopFuture` returned from `task`.
737737
@inlinable
738738
@preconcurrency
739-
public func flatSubmit<T: Sendable>(_ task: @escaping @Sendable () -> EventLoopFuture<T>) -> EventLoopFuture<T> { // TODO: This should take a closure that returns fresh
739+
public func flatSubmit<T: Sendable>(_ task: @escaping @Sendable () -> EventLoopFuture<T>) -> EventLoopFuture<T> {
740740
self.submit(task).flatMap { $0 }
741741
}
742742

‎Sources/NIOCore/EventLoopFuture.swift

+13-60
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,6 @@ public struct EventLoopPromise<Value> {
184184
self._resolve(value: .success(value))
185185
}
186186

187-
/// Deliver a successful result to the associated `EventLoopFuture<Value>` object.
188-
///
189-
/// - Note: The call to this method must happen on the same event loop as this promise was created from.
190-
///
191-
/// - parameters:
192-
/// - eventLoopBoundValue: The successful result of the operation.
193-
@inlinable
194-
public func succeed(eventLoopBoundValue: Value) {
195-
self._resolve(eventLoopBoundResult: .success(eventLoopBoundValue))
196-
}
197-
198187
/// Deliver an error to the associated `EventLoopFuture<Value>` object.
199188
///
200189
/// - parameters:
@@ -247,27 +236,6 @@ public struct EventLoopPromise<Value> {
247236
self._resolve(value: result)
248237
}
249238

250-
/// Complete the promise with the passed in `Result<Value, Error>`.
251-
///
252-
/// This method is equivalent to invoking:
253-
/// ```
254-
/// switch result {
255-
/// case .success(let value):
256-
/// promise.succeed(value)
257-
/// case .failure(let error):
258-
/// promise.fail(error)
259-
/// }
260-
/// ```
261-
///
262-
/// - Note: The call to this method must happen on the same event loop as this promise was created from.
263-
///
264-
/// - parameters:
265-
/// - result: The result which will be used to succeed or fail this promise.
266-
@inlinable
267-
public func completeWith(eventLoopBoundResult: Result<Value, Error>) {
268-
self._resolve(eventLoopBoundResult: eventLoopBoundResult)
269-
}
270-
271239
/// Fire the associated `EventLoopFuture` on the appropriate event loop.
272240
///
273241
/// This method provides the primary difference between the `EventLoopPromise` and most
@@ -287,23 +255,6 @@ public struct EventLoopPromise<Value> {
287255
}
288256
}
289257

290-
/// Fire the associated `EventLoopFuture` on the appropriate event loop.
291-
///
292-
/// This method provides the primary difference between the `EventLoopPromise` and most
293-
/// other `Promise` implementations: specifically, all callbacks fire on the `EventLoop`
294-
/// that was used to create the promise.
295-
///
296-
/// - Note: The call to this method must happen on the same event loop as this promise was created from.
297-
///
298-
/// - parameters:
299-
/// - value: The value to fire the future with.
300-
@inlinable
301-
internal func _resolve(eventLoopBoundResult: Result<Value, Error>) {
302-
self.futureResult.eventLoop.assertInEventLoop()
303-
304-
self._setValue(value: eventLoopBoundResult)._run()
305-
}
306-
307258
/// Set the future result and get the associated callbacks.
308259
///
309260
/// - parameters:
@@ -1435,17 +1386,17 @@ extension EventLoopFuture {
14351386
processResult(index, .success(()))
14361387
case .failure(let error):
14371388
processResult(index, .failure(error))
1438-
}
1439-
if case .failure = result {
1440-
return // Once the promise is failed, future results do not need to be processed.
1389+
return
14411390
}
14421391
} else {
14431392
// We have to map to `Void` here to avoid sharing the potentially non-Sendable
14441393
// value across event loops.
1445-
future
1446-
.map { _ in () }
1447-
.hop(to: eventLoop)
1448-
.whenComplete { result in processResult(index, result) }
1394+
future.whenComplete { result in
1395+
let voidResult = result.map { _ in }
1396+
future.eventLoop.execute {
1397+
processResult(index, voidResult)
1398+
}
1399+
}
14491400
}
14501401
}
14511402
}
@@ -1661,10 +1612,12 @@ extension EventLoopFuture {
16611612
} else {
16621613
// We have to map to `Void` here to avoid sharing the potentially non-Sendable
16631614
// value across event loops.
1664-
future
1665-
.map { _ in () }
1666-
.hop(to: eventLoop)
1667-
.whenComplete { result in processResult(index, result) }
1615+
future.whenComplete { result in
1616+
let voidResult = result.map { _ in }
1617+
future.eventLoop.execute {
1618+
processResult(index, voidResult)
1619+
}
1620+
}
16681621
}
16691622
}
16701623
}

0 commit comments

Comments
 (0)
Please sign in to comment.