Skip to content

Commit b290997

Browse files
committed
Update README
1 parent ac7e34d commit b290997

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,63 @@ struct MoviesView: View {
514514

515515
</details>
516516

517+
#### [AsyncPhaseAtom](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/asyncphaseatom)
518+
519+
| |Description|
520+
|:----------|:----------|
521+
|Summary |Provides an `AsyncPhase` value that represents a result of the given asynchronous throwable function.|
522+
|Output |`AsyncPhase<T, E: Error>` (`AsyncPhase<T, any Error>` in Swift 5)|
523+
|Use Case |Throwing or non-throwing asynchronous operation e.g. API call|
524+
525+
Note:
526+
The [typed throws](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0413-typed-throws.md) feature introduced in Swift 6 allows the `Failure` type of the produced `AsyncPhase` to be specified as any type or even non-throwing, but in Swift 5 without it, the `Failure` type is always be `any Error`.
527+
Here is a chart of the syntax in `typed throws` and the type of resulting `AsyncPhase`.
528+
529+
|Syntax |Shorthand |Produced |
530+
|:------------------|:------------------|:-------------------------|
531+
|`throws(E)` |`throws(E)` |`AsyncPhase<T, E>` |
532+
|`throws(any Error)`|`throws` |`AsyncPhase<T, any Error>`|
533+
|`throws(Never)` | |`AsyncPhase<T, Never>` |
534+
535+
<details><summary><code>📖 Example</code></summary>
536+
537+
```swift
538+
struct FetchTrendingSongsAtom: AsyncPhaseAtom, Hashable {
539+
func value(context: Context) async throws(FetchSongsError) -> [Song] {
540+
try await fetchTrendingSongs()
541+
}
542+
}
543+
544+
struct TrendingSongsView: View {
545+
@Watch(FetchTrendingSongsAtom())
546+
var phase
547+
548+
var body: some View {
549+
List {
550+
switch phase {
551+
case .success(let songs):
552+
ForEach(songs, id: \.id) { song in
553+
Text(song.title)
554+
}
555+
556+
case .failure(.noData):
557+
Text("There are no currently trending songs.")
558+
559+
case .failure(let error):
560+
Text(error.localizedDescription)
561+
}
562+
}
563+
}
564+
}
565+
```
566+
567+
</details>
568+
517569
#### [AsyncSequenceAtom](https://ra1028.github.io/swiftui-atom-properties/documentation/atoms/asyncsequenceatom)
518570

519571
| |Description|
520572
|:----------|:----------|
521-
|Summary |Provides a `AsyncPhase` value that represents asynchronous, sequential elements of the given `AsyncSequence`.|
573+
|Summary |Provides an `AsyncPhase` value that represents asynchronous, sequential elements of the given `AsyncSequence`.|
522574
|Output |`AsyncPhase<T, any Error>`|
523575
|Use Case |Handle multiple asynchronous values e.g. web-sockets|
524576

@@ -555,7 +607,7 @@ struct NotificationView: View {
555607

556608
| |Description|
557609
|:------------|:----------|
558-
|Summary |Provides a `AsyncPhase` value that represents sequence of values of the given `Publisher`.|
610+
|Summary |Provides an `AsyncPhase` value that represents sequence of values of the given `Publisher`.|
559611
|Output |`AsyncPhase<T, E: Error>`|
560612
|Use Case |Handle single or multiple asynchronous value(s) e.g. API call|
561613

0 commit comments

Comments
 (0)