DocC Concurrency Resources
No files matched your search
@@ -222,11 +222,11 @@ Despite the common guarantees and rules shared by database queues and pools, tho
|
||||
|
||||
``DatabaseQueue`` opens a single database connection, and serializes all database accesses, reads, and writes. There is never more than one thread that uses the database. In the image below, we see how three threads can see the database as time passes:
|
||||
|
||||

|
||||

|
||||
|
||||
``DatabasePool`` manages a pool of several database connections, and allows concurrent reads and writes thanks to the [WAL mode](https://www.sqlite.org/wal.html). A database pool serializes all writes (the <doc:Concurrency#Serialized-Writes> guarantee). Reads are isolated so that they don't see changes performed by other threads (the <doc:Concurrency#Isolated-Reads> guarantee). This gives a very different picture:
|
||||
|
||||

|
||||

|
||||
|
||||
See how, with database pools, two reads can see different database states at the same time. This may look scary! Please see the next chapter below for a relief.
|
||||
|
||||
@@ -330,7 +330,8 @@ Both ``DatabaseWriter/concurrentRead(_:)`` and ``DatabasePool/asyncConcurrentRea
|
||||
|
||||
In the illustration below, the striped band shows the delay needed for the reading thread to acquire isolation. Until then, no other thread can write:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Types that conform to ``TransactionObserver`` can also use those methods in their ``TransactionObserver/databaseDidCommit(_:)`` method, in order to process database changes without blocking other threads that want to write into the database.
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 122 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 124 KiB |