mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Added a missing new function
This commit is contained in:
parent
56d919af2c
commit
3261f12ea7
1 changed files with 19 additions and 7 deletions
|
@ -370,16 +370,28 @@ public extension GRDBStorage {
|
|||
}
|
||||
}
|
||||
|
||||
@discardableResult func write<T>(updates: (Database) throws -> Promise<T>) -> Promise<T> {
|
||||
@discardableResult func writeAsync<T>(updates: @escaping (Database) throws -> Promise<T>) -> Promise<T> {
|
||||
guard isValid, let dbWriter: DatabaseWriter = dbWriter else {
|
||||
return Promise(error: StorageError.databaseInvalid)
|
||||
}
|
||||
|
||||
do {
|
||||
return try dbWriter.write(updates)
|
||||
}
|
||||
catch {
|
||||
return Promise(error: error)
|
||||
}
|
||||
let (promise, seal) = Promise<T>.pending()
|
||||
|
||||
dbWriter.asyncWrite(
|
||||
{ db in
|
||||
try updates(db)
|
||||
.done { result in seal.fulfill(result) }
|
||||
.catch { error in seal.reject(error) }
|
||||
.retainUntilComplete()
|
||||
},
|
||||
completion: { _, result in
|
||||
switch result {
|
||||
case .failure(let error): seal.reject(error)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return promise
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue