Skip to content

Commit ac7e34d

Browse files
committed
Add documentation
1 parent c4b5eb5 commit ac7e34d

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

Sources/Atoms/Atom/AsyncPhaseAtom.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,76 @@
1+
/// An atom that provides an ``AsyncPhase`` value from the asynchronous throwable function.
2+
///
3+
/// The value produced by the given asynchronous throwable function will be converted into
4+
/// an enum representation ``AsyncPhase`` that changes when the process is done or thrown an error.
5+
///
6+
/// ## Output Value
7+
///
8+
/// ``AsyncPhase``<Self.Success, Self.Failure>
9+
///
10+
/// ## Example
11+
///
12+
/// ```swift
13+
/// struct AsyncTextAtom: AsyncPhaseAtom, Hashable {
14+
/// func value(context: Context) async throws -> String {
15+
/// try await Task.sleep(nanoseconds: 1_000_000_000)
16+
/// return "Swift"
17+
/// }
18+
/// }
19+
///
20+
/// struct DelayedTitleView: View {
21+
/// @Watch(AsyncTextAtom())
22+
/// var text
23+
///
24+
/// var body: some View {
25+
/// switch text {
26+
/// case .success(let text):
27+
/// Text(text)
28+
///
29+
/// case .suspending:
30+
/// Text("Loading")
31+
///
32+
/// case .failure:
33+
/// Text("Failed")
34+
/// }
35+
/// }
36+
/// ```
37+
///
138
public protocol AsyncPhaseAtom: AsyncAtom where Produced == AsyncPhase<Success, Failure> {
39+
/// The type of success value that this atom produces.
240
associatedtype Success
341

442
#if compiler(>=6)
43+
/// The type of errors that this atom produces.
544
associatedtype Failure: Error
645

46+
/// Asynchronously produces a value to be provided via this atom.
47+
///
48+
/// Values provided or errors thrown by this method are converted to the unified enum
49+
/// representation ``AsyncPhase``.
50+
///
51+
/// - Parameter context: A context structure to read, watch, and otherwise
52+
/// interact with other atoms.
53+
///
54+
/// - Throws: The error that occurred during the process of creating the resulting value.
55+
///
56+
/// - Returns: The process's result.
757
@MainActor
858
func value(context: Context) async throws(Failure) -> Success
959
#else
60+
/// The type of errors that this atom produces.
1061
typealias Failure = any Error
1162

63+
/// Asynchronously produces a value to be provided via this atom.
64+
///
65+
/// Values provided or errors thrown by this method are converted to the unified enum
66+
/// representation ``AsyncPhase``.
67+
///
68+
/// - Parameter context: A context structure to read, watch, and otherwise
69+
/// interact with other atoms.
70+
///
71+
/// - Throws: The error that occurred during the process of creating the resulting value.
72+
///
73+
/// - Returns: The process's result.
1274
@MainActor
1375
func value(context: Context) async throws -> Success
1476
#endif

Sources/Atoms/Atom/TaskAtom.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public protocol TaskAtom: AsyncAtom where Produced == Task<Success, Never> {
4646
/// - Parameter context: A context structure to read, watch, and otherwise
4747
/// interact with other atoms.
4848
///
49-
/// - Returns: A nonthrowing `Task` that produces asynchronous value.
49+
/// - Returns: The process's result.
5050
@MainActor
5151
func value(context: Context) async -> Success
5252
}

Sources/Atoms/Atom/ThrowingTaskAtom.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public protocol ThrowingTaskAtom: AsyncAtom where Produced == Task<Success, any
5050
///
5151
/// - Throws: The error that occurred during the process of creating the resulting value.
5252
///
53-
/// - Returns: A throwing `Task` that produces asynchronous value.
53+
/// - Returns: The process's result.
5454
@MainActor
5555
func value(context: Context) async throws -> Success
5656
}

0 commit comments

Comments
 (0)