-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(DOCSP-33483): Swift: Actor and Concurrency updates and fixes #3072
Conversation
Readability for Commit Hash: 16a9ee7 You can see any previous Readability scores (if they exist) by looking Readability scores for changed documents:
For Grade Level, aim for 8 or below. For Reading Ease scores, aim for 60 or above:
For help improving readability, try Hemingway App. |
|
||
// Create a todo item so there is something to observe | ||
try await realm.asyncWrite { | ||
return realm.create(Todo.self, value: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: return
isn't doing anything here
@globalActor actor BackgroundActor: GlobalActor { | ||
static var shared = BackgroundActor() | ||
|
||
public func deleteTodo(tsrToTodo tsr: ThreadSafeReference<Todo>) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you can put functions on a global actor, it'd be more common to have this be a top-level @BackgroudActor func
, and would serve better as documentation for global actor vs regular actor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've simplified a few of these examples to remove the global actor aspect. Is this more in line with what you had in mind, @tgoyne ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some random Q's from me, but overall LGTM
let actor = try await RealmActor() | ||
try await actor.createTodo(name: "Prepare fireworks for birthday party", owner: "Gandalf", status: "In Progress") | ||
|
||
// Later, get information off the actor-confined realm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might just be a snooty glitch but this doesn't format as a comment in the staged build, just fyi
@@ -37,7 +37,7 @@ simplify this for you. | |||
<ios-thread-safe-reference>` or :ref:`frozen objects <ios-frozen-objects>` | |||
across threads. | |||
|
|||
Actor-Isolated Realms | |||
Use Realm with Actors | |||
--------------------- | |||
|
|||
This page describes how to manually manage realm files and objects across threads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe there's a good reason for having it here, but it was confusing to me to have this as a section heading that also links out to a page with the same name. Maybe remove this heading and move this section to the top of the page as the intro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. I don't want the "go to some other page" to precede the intro here, but I'll remove the heading and just make this a part of the intro.
source/sdk/swift/crud/threading.txt
Outdated
@@ -90,11 +90,11 @@ Perform a Background Write | |||
.. versionadded:: 10.26.0 | |||
|
|||
You can add, modify, or delete objects in the background using | |||
:swift-sdk:`writeAsync <Structs/Realm.html#/s:10RealmSwift0A0V10writeAsync_10onCompletes6UInt32Vyyc_ys5Error_pSgcSgtF>`. | |||
:swift-sdk:`asyncWrite <Structs/Realm.html#/s:10RealmSwift0A0V10writeAsync_10onCompletes6UInt32Vyyc_ys5Error_pSgcSgtF>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this links out to writeAsync(_:onComplete:)
. is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah, it is and it isn't. I conflated the completion handler version of this API with the Swift async/awaitable version of this API (writeAsync
versus asyncWrite
). I've made a separate ticket to address this more broadly in the docs, but I'll revert these changes for now because this section is specifically concerned with the writeAsync
API.
✨ Staging URL: https://preview-mongodbmongodb.gatsbyjs.io/realm/master/ 🪵 Logs |
Pull Request Info
This PR:
writeAsync
mentions toasyncWrite
thaw()
with Swift actors, and recommendsThreadSafeReference
insteadJira
Staged Changes
Reminder Checklist
If your PR modifies the docs, you might need to also update some corresponding
pages. Check if completed or N/A.
Review Guidelines
REVIEWING.md