asyncBarrierWriteWithoutTransaction(_:)
Schedules database operations for execution, and returns immediately.
func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result<Database, Error>) -> Void)
Parameters
- updates
A closure which accesses the database. Its argument is a
Result
that provides the database connection, or the failure that would prevent establishing the barrier access to the database.
Database operations are not executed until all currently executing database accesses performed by the database writer finish executing (reads and writes). At that point, database operations are executed. Once they finish, the database writer can proceed with other database accesses.
For example:
writer.asyncBarrierWriteWithoutTransaction { dbResult in
do {
let db = try dbResult.get()
try Player(name: "Arthur").insert(db)
let newPlayerCount = try Player.fetchCount(db)
} catch {
// Handle error
}
}
Database operations run in the writer dispatch queue, serialized with all database updates performed by this DatabaseWriter
.
The Database
argument to updates
is valid only during the execution of the closure. Do not store or return the database connection for later use.