SE-0530: Async Result Support

Hi everyone,

The review of SE-0530 "Async Result Support" begins now and runs through May 12, 2026.

Reviews are an important part of the Swift evolution process. All review feedback should be either on this forum thread or, if you would like to keep your feedback private, directly to the review manager via the forum messaging feature. When contacting the review manager directly, please keep the proposal link at the top of the message.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  • What is your evaluation of the proposal?
  • Is the problem being addressed significant enough to warrant a change to Swift?
  • Does this proposal fit well with the feel and direction of Swift?
  • If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  • How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at https://github.com/swiftlang/swift-evolution/blob/main/process.md .

Thanks for contributing to Swift!

Doug Gregor
Review Manager

19 Likes

+1, this is a very welcome addition.

One other set of helpers I often find myself copying between projects (and have seen in other codebases) includes:

  • var isSuccess: Bool
  • var isFailure: Bool
  • var value: Success?
  • var error: Failure?
  • func mapAsVoid() -> Result<Void, Failure>
  • var infallibleValue: Success (where Failure == Never)

Would it be worth considering adding these as part of the standard Result API as well?

4 Likes

+1, I needed this last week and was happy to have come across the pitch thread.

I'm glad to see this is a targeted proposal and I think what's been proposed deserves to exist in the Standard Library. It fills a real hole in the API for the result of an async operation and feels natural. I don't have experience in other languages, but did find that when copying the implementation from the pitch thread it worked exactly as I needed it to. No comment on the ancillary ideas to augment Result from the pitch thread.

+1, have similar extension in several code-bases at this point. Would be good to see it in the standard library.

1 Like

I am firmly in favour of adding this interface. It's long overdue! I think the result of the body closure might need to be sending?

The Result type already effectively has all of these interfaces:

Proposed Real
isSuccess case .success
isFailure case .failure
value try? get() or case .success(let value)
error case .failure(let error)
mapAsVoid() map { _ in }
infallibleValue get()

I recognize the ergonomics of all these alternatives aren't the same (in particular, pattern-matching with case isn't always usable in place of an expression) but a proposal to add some or all of these interfaces would need to firmly establish that they're a significant improvement.

2 Likes

No it doesn't have to. The closure is nonisolated(nonsending) and Result is conditionally Sendable on Success. This means that the value returned from body will be tied to the current isolation region. Similarly, the Result itself will be tied to the current isolation region. This means it cannot be sent across isolation domains.

3 Likes

+1 That looks great! I'm wondering if this would work with typed throw tho? Or would it need some explicit Result<Bool, SomeTypedError> to avoid loosing the error type?

Half of those are good and the others are not accurate mappings.

We could bring it up in another new thread (because it's not relevant here) but much chat has been had about a more verbose form of the following.

Specialized to Result :frowning: Same syntax as any other enum :slightly_smiling_face:
isSuccess is .success
isFailure is .failure
error as? .failure

That is why that API has not been accepted on Result yet; it feels like it might be better as a general improvement to enum pattern-matching.

At any rate, we don't need to discuss this further in this review. This API is a reasonable addition on its own, and it's okay for proposals to be narrow. Other additions should be separately pitched.

5 Likes

This proposal has been accepted, thank you everyone!

Doug

7 Likes