Skip to content

Commit 04a9a20

Browse files
committed
Update README.md
1 parent 10ba852 commit 04a9a20

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,54 @@ There are two strategies
2424

2525
```
2626

27+
## How to use
28+
29+
```swift
30+
final class ViewModel : ObservableObject{
31+
32+
func constant() async {
33+
let policy = RetryService(strategy: .constant())
34+
for delay in policy{
35+
try? await Task.sleep(nanoseconds: delay)
36+
// do something
37+
}
38+
}
39+
40+
func exponential() async {
41+
let policy = RetryService(
42+
strategy: .exponential(
43+
retry: 5,
44+
multiplier: 2,
45+
duration: .seconds(1),
46+
timeout: .seconds(5)
47+
)
48+
)
49+
50+
for delay in policy{
51+
try? await Task.sleep(nanoseconds: delay)
52+
// do something
53+
}
54+
}
55+
}
56+
57+
struct ContentView: View {
58+
59+
@StateObject var model = ViewModel()
60+
61+
var body: some View {
62+
VStack {
63+
Button("constatnt") { Task { await model.constant() } }
64+
Button("exponential") { Task { await model.exponential() } }
65+
}
66+
.padding()
67+
.task {
68+
await model.exponential()
69+
}
70+
71+
}
72+
}
73+
```
74+
2775
## Packages using the package
2876

2977
[Async http client](https://github.com/The-Igor/async-http-client)

0 commit comments

Comments
 (0)