From 2b549c358d9950b5efd16938cd91448e06ee005d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 27 Mar 2016 14:54:46 +0200 Subject: [PATCH 1/3] README.md --- README.md | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7c2432516..a2c8dc5a4 100644 --- a/README.md +++ b/README.md @@ -2555,23 +2555,31 @@ dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write let count1 = PointOfInterest.fetchCount(db) let count2 = PointOfInterest.fetchCount(db) } - -dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write - // Now this value may be different: - let count = PointOfInterest.fetchCount(db) -} ``` -*However, isolation is lost when you access database queues and pools in an unprotected fashion.* The two lines below are equivalent to two consecutive calls to `dbQueue.inDatabase` or `dbPool.read`, with the opportunity for other threads to sneak in between: +Two consecutive calls don't guarantee isolation: ```swift // Those two values may be different because some other thread may have inserted // or deleted a point of interest between the two statements: -let count1 = PointOfInterest.fetchCount(dbQueue) // or dbPool -let count2 = PointOfInterest.fetchCount(dbQueue) // or dbPool +let count1 = dbQueue.inDatabase { db in + return PointOfInterest.fetchCount(db) +} +let count2 = dbQueue.inDatabase { db in + return PointOfInterest.fetchCount(db) +} ``` -That being said, unprotected access can do everything but iterate the memory-efficient [database sequences](#fetching-methods): +Isolation is also lost when you access database queues and pools in an unprotected fashion. The two lines below are equivalent to two consecutive calls to `dbQueue.inDatabase`, as above, with the opportunity for other threads to sneak in between: + +```swift +// Those two values may be different because some other thread may have inserted +// or deleted a point of interest between the two statements: +let count1 = PointOfInterest.fetchCount(dbQueue) +let count2 = PointOfInterest.fetchCount(dbQueue) +``` + +That being said, unprotected access can do everything (but iterate the memory-efficient [database sequences](#fetching-methods)): ```swift // Unprotected access, for advanced users only: From 98bc81cdd59777f8ffc0763df7cf12d4965f44cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 27 Mar 2016 14:56:44 +0200 Subject: [PATCH 2/3] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2c8dc5a4..2854c2edb 100644 --- a/README.md +++ b/README.md @@ -2557,7 +2557,7 @@ dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write } ``` -Two consecutive calls don't guarantee isolation: +Isolation is only guaranteed inside the closure argument of those methods: two consecutive calls don't guarantee isolation: ```swift // Those two values may be different because some other thread may have inserted From e180ae4cbdd3060aa8c0a5e28cb6b7710d4fd788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 27 Mar 2016 15:00:49 +0200 Subject: [PATCH 3/3] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2854c2edb..e603e2578 100644 --- a/README.md +++ b/README.md @@ -2557,7 +2557,7 @@ dbQueue.inDatabase { db in // or dbPool.read, or dbPool.write } ``` -Isolation is only guaranteed inside the closure argument of those methods: two consecutive calls don't guarantee isolation: +Isolation is only guaranteed *inside* the closure argument of those methods. Two consecutive calls don't guarantee isolation: ```swift // Those two values may be different because some other thread may have inserted