-
-
Notifications
You must be signed in to change notification settings - Fork 4
Cross-platform observation delivery + WebAssembly build support #152
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #if !os(Linux) && !os(Windows) | ||
| #if canImport(SwiftUI) | ||
| import SwiftUI | ||
|
|
||
| extension Application { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ extension Application { | |
| ) | ||
| } | ||
|
|
||
| #if (!os(Linux) && !os(Windows)) | ||
| #if canImport(ObjectiveC) | ||
| if NSClassFromString("XCTest") == nil { | ||
| Task { | ||
| await MainActor.run { | ||
|
|
@@ -149,6 +149,8 @@ extension Application { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| shared.notifyChange() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since To prevent this, we should ensure Alternative: A cleaner approach would be to make if Thread.isMainThread {
shared.notifyChange()
} else {
DispatchQueue.main.async {
shared.notifyChange()
}
} |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,8 @@ extension Application { | |
| userDefaults.set(newValue, forKey: scope.key) | ||
| } | ||
| } | ||
|
|
||
| shared.notifyChange() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since To prevent this, we should ensure Alternative: A cleaner approach would be to make if Thread.isMainThread {
shared.notifyChange()
} else {
DispatchQueue.main.async {
shared.notifyChange()
}
} |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,8 @@ extension Application { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| shared.notifyChange() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since To prevent this, we should ensure Alternative: A cleaner approach would be to make if Thread.isMainThread {
shared.notifyChange()
} else {
DispatchQueue.main.async {
shared.notifyChange()
}
} |
||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Since
Application.DependencySliceis not restricted to@MainActor, its setter can be invoked from background threads (e.g., when a background service updates its state). CallingApplication.shared.notifyChange()directly on a background thread will trigger the assertionassert(Thread.isMainThread)insidenotifyChange()and crash the application.To prevent this, we should ensure
notifyChange()is always dispatched to the main thread.Alternative: A cleaner approach would be to make
Application.notifyChange()itself thread-safe by internally checkingThread.isMainThreadand dispatching toDispatchQueue.mainif necessary, which would eliminate the need for these checks at every call site.