@@ -19,10 +19,10 @@ public class SourceEditor {
1919 case scrollPositionChanged
2020 }
2121
22- public let axNotifications = AsyncPassthroughSubject < AXNotification > ( )
2322 let runningApplication : NSRunningApplication
2423 public let element : AXUIElement
2524 var observeAXNotificationsTask : Task < Void , Never > ?
25+ public let axNotifications = AsyncPassthroughSubject < AXNotification > ( )
2626
2727 /// The content of the source editor.
2828 public var content : Content {
@@ -53,18 +53,14 @@ public class SourceEditor {
5353 public init ( runningApplication: NSRunningApplication , element: AXUIElement ) {
5454 self . runningApplication = runningApplication
5555 self . element = element
56-
57- Task { @MainActor in
58- observeAXNotifications ( )
59- }
56+ observeAXNotifications ( )
6057 }
6158
62- @MainActor
63- func observeAXNotifications( ) {
59+ private func observeAXNotifications( ) {
6460 observeAXNotificationsTask? . cancel ( )
6561 observeAXNotificationsTask = Task { @MainActor [ weak self] in
6662 guard let self else { return }
67- await withTaskGroup ( of: Void . self) { [ weak self] group in
63+ await withThrowingTaskGroup ( of: Void . self) { [ weak self] group in
6864 guard let self else { return }
6965 let editorNotifications = AXNotificationStream (
7066 app: runningApplication,
@@ -76,6 +72,7 @@ public class SourceEditor {
7672
7773 group. addTask { [ weak self] in
7874 for await notification in editorNotifications {
75+ try Task . checkCancellation ( )
7976 guard let self else { return }
8077 if let kind: AXNotificationKind = {
8178 switch notification. name {
@@ -101,6 +98,7 @@ public class SourceEditor {
10198
10299 group. addTask { [ weak self] in
103100 for await notification in scrollViewNotifications {
101+ try Task . checkCancellation ( )
104102 guard let self else { return }
105103 self . axNotifications. send ( . init(
106104 kind: . scrollPositionChanged,
@@ -110,7 +108,7 @@ public class SourceEditor {
110108 }
111109 }
112110
113- await group. waitForAll ( )
111+ try ? await group. waitForAll ( )
114112 }
115113 }
116114 }
0 commit comments