Skip to content

Commit 62374db

Browse files
committed
add example for async await into readme
1 parent 91ac56f commit 62374db

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,45 @@ storage.async.removeExpiredObjects() { result in
288288
}
289289
```
290290

291+
#### Swift Concurrency
292+
293+
```swift
294+
do {
295+
try await storage.async.setObject("Oslo", forKey: "my favorite city")
296+
print("saved successfully")
297+
} catch {
298+
print(error)
299+
}
300+
301+
do {
302+
let city = try await storage.async.object(forKey: "my favorite city")
303+
print("my favorite city is \(city)")
304+
} catch {
305+
print(error)
306+
}
307+
308+
do {
309+
let exists = try await storage.async.objectExists(forKey: "my favorite city")
310+
if exists {
311+
print("I have a favorite city")
312+
}
313+
} catch {}
314+
315+
do {
316+
try await storage.async.remoeAll()
317+
print("removal completes")
318+
} catch {
319+
print(error)
320+
}
321+
322+
do {
323+
try await storage.async.removeExpiredObjects()
324+
print("removal completes")
325+
} catch {
326+
print(error)
327+
}
328+
```
329+
291330
### Expiry date
292331

293332
By default, all saved objects have the same expiry as the expiry you specify in `DiskConfig` or `MemoryConfig`. You can overwrite this for a specific object by specifying `expiry` for `setObject`

0 commit comments

Comments
 (0)