Add an optional target queue to for database operations#801
Open
sharplet wants to merge 2 commits intostephencelis:masterfrom
Open
Add an optional target queue to for database operations#801sharplet wants to merge 2 commits intostephencelis:masterfrom
sharplet wants to merge 2 commits intostephencelis:masterfrom
Conversation
The optional target queue is useful for synchronising other work with respect to database operations. Provided the target queue is also a serial queue, work submitted to the private connection queue and work submitted directly to the target queue will still be executed in serial. The queue context is now set on the target queue if present. The connection queue inherits values set on the target queue, so the call to `DispatchQueue.getSpecific`, using `queueKey`, returns `queueContext` as expected. For this logic to still be thread-safe, the target queue must be a serial queue. `queueKey` is now an instance variable so that every connection gets a unique key, ensuring that connections can't write over one another's context variables. The `attributes:` parameter is also removed from the call to initialise the database queue, as `[]` (i.e., serial) is already the default.
jberkel
reviewed
Aug 21, 2021
| /// synchronized with respect to database operations. | ||
| /// | ||
| /// **Important:** The target queue **must not** be a concurrent queue, or access | ||
| /// to the returned connection is no longer guaranteed be thread-safe. |
Collaborator
There was a problem hiding this comment.
could this be asserted in code?
Author
There was a problem hiding this comment.
That would be nice! Currently I'm not aware of public API to check whether a queue is serial or concurrent. 🤔
Collaborator
|
Perhaps related to #937 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The optional target queue is useful for synchronising other work with respect to database operations. Provided the target queue is also a serial queue, work submitted to the private connection queue and work submitted directly to the target queue will still be executed in serial.
The queue context is now set on the target queue if present. The connection queue inherits values set on the target queue, so the call to
DispatchQueue.getSpecific, usingqueueKey, returnsqueueContextas expected. For this logic to still be thread-safe, the target queue must be a serial queue.queueKeyis now an instance variable so that every connection gets a unique key, ensuring that connections can't write over one another's context variables.The
attributes:parameter is also removed from the call to initialise the database queue, as[](i.e., serial) is already the default.