-
Notifications
You must be signed in to change notification settings - Fork 7
@MainActor annotations #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ff8b040
Mostly @MainActor-y
lickel 9dea786
Further slicing
lickel b6a5736
Unsafe main thread annotation
lickel d5dfc3b
Typealiases / formatting
lickel f472e70
Remove one main actor
lickel d48b37b
Tests
lickel 07d57d6
Lint
lickel 8148979
more delegates
lickel cebdc8c
Changelog
lickel 2c03f35
Better changelog
lickel 6570bae
A few more annotations
lickel f3b25b3
Cleanup some missing MainActor assumptoins
lickel fdb8dee
A few more annotations
lickel 013f7f0
Even more
lickel 585910e
Support less main-thread completions
lickel 3f932c3
Fixup
lickel e035de6
Cleanup Delegates
lickel 2985eaa
Merge branch 'feature/5.0' into mainactor
lickel 7645cac
typo
lickel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,11 +75,26 @@ internal class LegacyKeyValueObserving<Object: NSObject, Value: Any>: NSObject, | |
|
|
||
| private var unsafeIsObserving = true | ||
|
|
||
| convenience init(object: Object, keyPath: AnyKeyPath, type: Value.Type, handler: @escaping Handler) { | ||
| self.init(object: object, keyPath: keyPath._kvcKeyPathString!, type: type, handler: handler) | ||
| convenience init( | ||
| object: Object, | ||
| keyPath: AnyKeyPath, | ||
| type: Value.Type, | ||
| handler: @escaping Handler | ||
| ) { | ||
| self.init( | ||
| object: object, | ||
| keyPath: keyPath._kvcKeyPathString!, | ||
| type: type, | ||
| handler: handler | ||
| ) | ||
| } | ||
|
|
||
| init(object: Object, keyPath: String, type: Value.Type, handler: @escaping Handler) { | ||
| init( | ||
| object: Object, | ||
| keyPath: String, | ||
| type: Value.Type, | ||
| handler: @escaping Handler | ||
| ) { | ||
| self.object = object | ||
| self.keyPath = keyPath | ||
| self.handler = handler | ||
|
|
@@ -107,9 +122,22 @@ internal class LegacyKeyValueObserving<Object: NSObject, Value: Any>: NSObject, | |
| } | ||
|
|
||
| // swiftlint:disable:next block_based_kvo | ||
| override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { | ||
| guard let typedObject = object as? Object, typedObject == self.object, keyPath == self.keyPath else { | ||
| return super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) | ||
| override func observeValue( | ||
| forKeyPath keyPath: String?, | ||
| of object: Any?, | ||
| change: [NSKeyValueChangeKey: Any]?, | ||
| context: UnsafeMutableRawPointer? | ||
| ) { | ||
| guard let typedObject = object as? Object, | ||
| typedObject == self.object, | ||
| keyPath == self.keyPath | ||
| else { | ||
| return super.observeValue( | ||
| forKeyPath: keyPath, | ||
| of: object, | ||
| change: change, | ||
| context: context | ||
| ) | ||
| } | ||
|
|
||
| let oldValue = change?[.oldKey] as? Value | ||
|
|
@@ -120,7 +148,9 @@ internal class LegacyKeyValueObserving<Object: NSObject, Value: Any>: NSObject, | |
| } | ||
|
|
||
| internal class FetchRequestObservableToken<Parameter>: ObservableToken { | ||
| private let _observe: (_ handler: @escaping (Parameter) -> Void) -> Void | ||
| typealias Handler = (Parameter) -> Void | ||
|
Collaborator
Author
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. Making this @mainactor (which requires making ObservableToken's handler @mainactor) was a giant pain and not worth it since I could do the simple main-thread bouncing behavior. |
||
|
|
||
| private let _observe: (_ handler: @escaping Handler) -> Void | ||
| private let _invalidate: () -> Void | ||
|
|
||
| var isObserving: Bool { | ||
|
|
@@ -131,7 +161,10 @@ internal class FetchRequestObservableToken<Parameter>: ObservableToken { | |
|
|
||
| private var unsafeIsObserving = false | ||
|
|
||
| private init(observe: @escaping (_ handler: @escaping (Parameter) -> Void) -> Void, invalidate: @escaping () -> Void) { | ||
| private init( | ||
| observe: @escaping (_ handler: @escaping Handler) -> Void, | ||
| invalidate: @escaping () -> Void | ||
| ) { | ||
| _observe = observe | ||
| _invalidate = invalidate | ||
| } | ||
|
|
@@ -141,7 +174,7 @@ internal class FetchRequestObservableToken<Parameter>: ObservableToken { | |
| _invalidate = { token.invalidate() } | ||
| } | ||
|
|
||
| func observeIfNeeded(handler: @escaping (Parameter) -> Void) { | ||
| func observeIfNeeded(handler: @escaping Handler) { | ||
| synchronized(self) { | ||
| guard !unsafeIsObserving else { | ||
| return | ||
|
|
@@ -154,7 +187,7 @@ internal class FetchRequestObservableToken<Parameter>: ObservableToken { | |
| } | ||
| } | ||
|
|
||
| func observe(handler: @escaping (Parameter) -> Void) { | ||
| func observe(handler: @escaping Handler) { | ||
| synchronized(self) { | ||
| _observe(handler) | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
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 runs "clean".
Full concurrency checking would fail in many ways (notably
@MainActor(unsafe)does not work).