File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments