Database.afterNextTransactionCommit(_:): document that the closure runs in a protected dispatch queue

This commit is contained in:
Gwendal Roué authored and Gwendal Roué committed 2017-06-20 07:54:19 +02:00
1 parent da48b0880e
commit 66c2b72a28
1 file changed
+4 -2
+4 -2
View File
@@ -4074,9 +4074,9 @@ Database observation requires that a single [database queue](#database-queues) o
### After Commit Hook
**When an application needs to make sure a database transaction has been successfully committed before it executes some work, use the `Database.afterNextTransactionCommit(_:)` method.**
**When your application needs to make sure a database transaction has been successfully committed before it executes some work, use the `Database.afterNextTransactionCommit(_:)` method.**
Its closure argument is called after database changes have been successfully written to disk:
Its closure argument is called right after database changes have been successfully written to disk:
```swift
dbQueue.inTransaction { db in
@@ -4088,6 +4088,8 @@ dbQueue.inTransaction { db in
}
```
The closure runs in a protected dispatch queue, serialized with all database updates.
**This "after commit hook" helps synchronizing the database with other resources, such as files, or system sensors.**
In the example below, a [location manager](https://developer.apple.com/documentation/corelocation/cllocationmanager) starts monitoring a CLRegion if and only if it has successfully been stored in the database: