Skip to content

Commit 3fdb0aa

Browse files
committed
add async await
1 parent f44a8f6 commit 3fdb0aa

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Source/Shared/Storage/AsyncStorage.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,65 @@ public extension AsyncStorage {
138138
return storage
139139
}
140140
}
141+
142+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
143+
public extension AsyncStorage {
144+
func entry(forKey key: Key) async throws -> Entry<Value> {
145+
try await withCheckedThrowingContinuation { continuation in
146+
entry(forKey: key) {
147+
continuation.resume(with: $0)
148+
}
149+
}
150+
}
151+
152+
func removeObject(forKey key: Key) async throws {
153+
try await withCheckedThrowingContinuation { continuation in
154+
removeObject(forKey: key) {
155+
continuation.resume(with: $0)
156+
}
157+
}
158+
}
159+
160+
func setObject(
161+
_ object: Value,
162+
forKey key: Key,
163+
expiry: Expiry? = nil) async throws {
164+
try await withCheckedThrowingContinuation { continuation in
165+
setObject(object, forKey: key, expiry: expiry) {
166+
continuation.resume(with: $0)
167+
}
168+
}
169+
}
170+
171+
func removeAll() async throws {
172+
try await withCheckedThrowingContinuation { continuation in
173+
removeAll {
174+
continuation.resume(with: $0)
175+
}
176+
}
177+
}
178+
179+
func removeExpiredObjects() async throws {
180+
try await withCheckedThrowingContinuation { continuation in
181+
removeExpiredObjects {
182+
continuation.resume(with: $0)
183+
}
184+
}
185+
}
186+
187+
func object(forKey key: Key) async throws -> Value {
188+
try await withCheckedThrowingContinuation { continuation in
189+
object(forKey: key) {
190+
continuation.resume(with: $0)
191+
}
192+
}
193+
}
194+
195+
func objectExists(forKey key: Key) async throws -> Bool {
196+
try await withCheckedThrowingContinuation { continuation in
197+
objectExists(forKey: key) {
198+
continuation.resume(with: $0)
199+
}
200+
}
201+
}
202+
}

0 commit comments

Comments
 (0)