Skip to content
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

Merged
merged 11 commits into from
Nov 14, 2023

Conversation

dacharyc
Copy link
Collaborator

@dacharyc dacharyc commented Nov 6, 2023

Pull Request Info

This PR:

  • Fixes and un-skips failing tests showing invalid examples of using Realm with Swift Actors
  • Corrects writeAsync mentions to asyncWrite
  • Corrects the conflated "Observe Notifications on an Actor-Isolated Realm" to "Observe Notifications on a Different Actor"
  • Adds more details about how to use Realm across actors based on docs feedback
  • Notes you can't currently use thaw() with Swift actors, and recommends ThreadSafeReference instead

Jira

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.

  • Create Jira ticket for corresponding docs-app-services update(s), if any
  • Checked/updated Admin API
  • Checked/updated CLI reference

Review Guidelines

REVIEWING.md

Copy link

github-actions bot commented Nov 6, 2023

Readability for Commit Hash: 16a9ee7

You can see any previous Readability scores (if they exist) by looking
at the comment's history.

Readability scores for changed documents:

  • source/sdk/swift: Grade Level: 9.6, Reading Ease: 49.62
  • source/sdk/swift/swift-concurrency: Grade Level: 9.6, Reading Ease: 54.93
  • source/sdk/swift/react-to-changes: Grade Level: 10.4, Reading Ease: 47.69
  • source/sdk/swift/use-realm-with-actors: Grade Level: 9.5, Reading Ease: 55.44
  • source/sdk/swift/crud/create: Grade Level: 10.5, Reading Ease: 47.28
  • source/sdk/swift/crud/threading: Grade Level: 7.8, Reading Ease: 65.12
  • source/sdk/swift/crud/delete: Grade Level: 6.4, Reading Ease: 68.67
  • source/sdk/swift/crud/update: Grade Level: 9.2, Reading Ease: 50.84

For Grade Level, aim for 8 or below.

For Reading Ease scores, aim for 60 or above:

Score Difficulty
90-100 Very Easy
80-89 Easy
70-79 Fairly Easy
60-69 Medium
50-59 Fairly Hard
30-49 Hard
0-29 Very Hard

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: [
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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 ?

Copy link
Collaborator

@cbullinger cbullinger left a 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

source/sdk/swift/react-to-changes.txt Show resolved Hide resolved
source/sdk/swift/use-realm-with-actors.txt Outdated Show resolved Hide resolved
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
Copy link
Collaborator

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

source/sdk/swift/use-realm-with-actors.txt Show resolved Hide resolved
source/sdk/swift/use-realm-with-actors.txt Outdated Show resolved Hide resolved
source/sdk/swift/use-realm-with-actors.txt Outdated Show resolved Hide resolved
@@ -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.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 Show resolved Hide resolved
@@ -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>`.
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

source/sdk/swift/crud/threading.txt Outdated Show resolved Hide resolved
@dacharyc dacharyc merged commit 7c2d7cb into mongodb:master Nov 14, 2023
6 checks passed
@dacharyc dacharyc deleted the DOCSP-33483 branch November 14, 2023 16:16
@docs-builder-bot
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants