-
Notifications
You must be signed in to change notification settings - Fork 721
Add more methods to work with Isolated futures #3117
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,6 +389,43 @@ extension EventLoopFuture { | |
| return next.futureResult.assumeIsolatedUnsafeUnchecked() | ||
| } | ||
|
|
||
| /// When the current `EventLoopFuture<Value>.Isolated` is in an error state, run the provided callback, which | ||
| /// may recover from the error by returning an `EventLoopFuture<NewValue>.Isolated`. The callback is intended to potentially | ||
| /// recover from the error by returning a new `EventLoopFuture.Isolated` that will eventually contain the recovered | ||
| /// result. | ||
| /// | ||
| /// If the callback cannot recover it should return a failed `EventLoopFuture.Isolated`. | ||
| /// | ||
| /// - Note: The `Value` need not be `Sendable` since the isolation domains of this future and the future returned from the callback | ||
| /// must be the same | ||
| /// | ||
| /// - Parameters: | ||
| /// - callback: Function that will receive the error value of this `EventLoopFuture.Isolated` and return | ||
| /// a new value lifted into a new `EventLoopFuture.Isolated`. | ||
| /// - Returns: A future that will receive the recovered value. | ||
| @inlinable | ||
| @available(*, noasync) | ||
| public func flatMapError( | ||
| _ callback: @escaping (Error) -> EventLoopFuture<Value>.Isolated | ||
| ) -> EventLoopFuture<Value>.Isolated { | ||
| let next = EventLoopPromise<Value>.makeUnleakablePromise(eventLoop: self._wrapped.eventLoop) | ||
| let base = self._wrapped | ||
|
|
||
| base._whenCompleteIsolated { | ||
| switch base._value! { | ||
| case .success(let t): | ||
| return next._setValue(value: .success(t)) | ||
| case .failure(let e): | ||
| let t = callback(e) | ||
| t._wrapped.eventLoop.assertInEventLoop() | ||
| return t._wrapped._addCallback { | ||
| next._setValue(value: t._wrapped._value!) | ||
| } | ||
| } | ||
| } | ||
| return next.futureResult.assumeIsolatedUnsafeUnchecked() | ||
| } | ||
|
|
||
| /// When the current `EventLoopFuture<Value>` is fulfilled, run the provided callback, which | ||
| /// performs a synchronous computation and returns either a new value (of type `NewValue`) or | ||
| /// an error depending on the `Result` returned by the closure. | ||
|
|
@@ -643,6 +680,11 @@ extension EventLoopPromise { | |
| self._wrapped = _wrapped | ||
| } | ||
|
|
||
| @usableFromInline | ||
| var futureResult: EventLoopFuture<Value>.Isolated { | ||
|
||
| self._wrapped.futureResult.assumeIsolated() | ||
| } | ||
|
|
||
| /// Deliver a successful result to the associated `EventLoopFuture<Value>` object. | ||
| /// | ||
| /// - Parameters: | ||
|
|
@@ -708,3 +750,4 @@ extension EventLoopPromise { | |
|
|
||
| @available(*, unavailable) | ||
| extension EventLoopPromise.Isolated: Sendable {} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.