Skip to content

Commit 390d011

Browse files
authored
Add reasync initializer to Result (#15)
1 parent 6155400 commit 390d011

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extension Result where Failure == Swift.Error {
2+
/// Creates a new result by evaluating an async throwing closure, capturing the returned value as
3+
/// a success, or any thrown error as a failure.
4+
///
5+
/// - Parameter body: A throwing closure to evaluate.
6+
@_transparent
7+
public init(catching body: () async throws -> Success) async {
8+
do {
9+
self = .success(try await body())
10+
} catch {
11+
self = .failure(error)
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)