From 8580023eda86117e6cf707bfc806b63e97ccd7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 1 Sep 2019 16:46:17 +0200 Subject: [PATCH] DatabasePool.barrierWriteWithoutTransaction --- GRDB/Core/DatabasePool.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 60a3e1bee..927ad74fc 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -636,6 +636,22 @@ extension DatabasePool: DatabaseReader { return try writer.sync(updates) } + /// A barrier write ensures that no database access is executed until all + /// previous accesses have completed, and the specified updates have been + /// executed. + /// + /// This method is *not* reentrant. + /// + /// - important: Reads executed by concurrent *database snapshots* are not + /// considered: they can run concurrently with the barrier updates. + /// - parameter updates: The updates to the database. + /// - throws: The error thrown by the updates. + public func barrierWriteWithoutTransaction(_ updates: (Database) throws -> T) rethrows -> T { + return try readerPool.barrier { + try writer.sync(updates) + } + } + /// Synchronously executes database updates in a protected dispatch queue, /// wrapped inside a transaction, and returns the result. ///