Skip to content

Commit 26f3caf

Browse files
committed
Update readme
1 parent 717f622 commit 26f3caf

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
# AsyncObservable
22

3+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmeech-ward%2FAsyncObservable%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/meech-ward/AsyncObservable)
4+
5+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmeech-ward%2FAsyncObservable%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/meech-ward/AsyncObservable)
6+
7+
The API is probably stable. Let me know if the API should change, otherwise this API will get bumped to 1.0.0.
8+
9+
```swift
10+
// values
11+
asyncObservable.value
12+
asyncObservable.valueStream
13+
asyncObservable.valueObservable
14+
15+
// updates
16+
asyncObservable.update(2)
17+
asyncObservable.update { $0 + 1 }
18+
asyncObservable.mutate { $0.append(4) }
19+
```
20+
321
Some of the features that Combine used to offer, but using Swift concurrency and @Observable instead. So it's more compatible with modern setups and should work just fine on any platform.
422
Designed for Swift 6.
523

6-
724
A single property that is thread safe and can be observed using async streams or @Observable.
825

926
```swift
@@ -33,10 +50,9 @@ struct SomethingView: View {
3350
}
3451
```
3552

36-
3753
## Stream
3854

39-
The streams buffering policy defaults to `.unbounded`, so it will "gather" values as soon as you create it.
55+
The streams buffering policy defaults to `.unbounded`, so it will "gather" values as soon as you create it.
4056

4157
```swift
4258
let someProperty = AsyncObservable(1)
@@ -79,7 +95,7 @@ let stream = someProperty.valueStream // already has 1
7995
// only print first value
8096
for await value in stream {
8197
print(value) // 1
82-
break
98+
break
8399
}
84100

85101
// don't do this ❌
@@ -89,7 +105,7 @@ for await value in stream {
89105

90106
// do this ✅
91107
for await value in someProperty.valueStream {
92-
108+
93109
}
94110
```
95111

@@ -103,8 +119,7 @@ let values = AsyncObservable([1, 2, 3])
103119
values.mutate { $0.append(4) }
104120
```
105121

106-
107-
## Buffering Policy
122+
## Buffering Policy
108123

109124
The buffering policy defaults to `.unbounded`, but you can change it on init.
110125

@@ -127,4 +142,3 @@ Use the `AsyncObservableUserDefaults` class to store values in UserDefaults. Wor
127142
```swift
128143
let someProperty = AsyncObservableUserDefaults("someKey", initialValue: "Hello, world!")
129144
```
130-

0 commit comments

Comments
 (0)