Title: [279465] trunk/Source/WebKit
Revision
279465
Author
jer.no...@apple.com
Date
2021-07-01 09:34:58 -0700 (Thu, 01 Jul 2021)

Log Message

[Mac] Adopt async GroupActivity.sessions() iterable instead of GroupSessionObserver
https://bugs.webkit.org/show_bug.cgi?id=227548
<rdar://78240035>

Reviewed by Sam Weinig.

Rather than adopting GroupSessionObserver, which requires Combine, GroupActivity.sessions()
uses AsyncSequence, a new Swift 5.5 feature, to allow clients to be notified that new
sessions are avaliable.

* UIProcess/Cocoa/GroupActivities/WKGroupSession.swift:
(WKGroupSessionObserver.incomingSessionsTask):
(WKGroupSessionObserver.receivedSession(_:)):
(WKGroupSessionObserver.cancellables): Deleted.
(WKGroupSessionObserver.recievedSession(_:)): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279464 => 279465)


--- trunk/Source/WebKit/ChangeLog	2021-07-01 15:58:00 UTC (rev 279464)
+++ trunk/Source/WebKit/ChangeLog	2021-07-01 16:34:58 UTC (rev 279465)
@@ -1,3 +1,21 @@
+2021-07-01  Jer Noble  <jer.no...@apple.com>
+
+        [Mac] Adopt async GroupActivity.sessions() iterable instead of GroupSessionObserver
+        https://bugs.webkit.org/show_bug.cgi?id=227548
+        <rdar://78240035>
+
+        Reviewed by Sam Weinig.
+
+        Rather than adopting GroupSessionObserver, which requires Combine, GroupActivity.sessions()
+        uses AsyncSequence, a new Swift 5.5 feature, to allow clients to be notified that new
+        sessions are avaliable.
+
+        * UIProcess/Cocoa/GroupActivities/WKGroupSession.swift:
+        (WKGroupSessionObserver.incomingSessionsTask):
+        (WKGroupSessionObserver.receivedSession(_:)):
+        (WKGroupSessionObserver.cancellables): Deleted.
+        (WKGroupSessionObserver.recievedSession(_:)): Deleted.
+
 2021-07-01  Youenn Fablet  <you...@apple.com>
 
         [Cocoa] Migrate WebRTC UDP socket handling to NW API

Modified: trunk/Source/WebKit/UIProcess/Cocoa/GroupActivities/WKGroupSession.swift (279464 => 279465)


--- trunk/Source/WebKit/UIProcess/Cocoa/GroupActivities/WKGroupSession.swift	2021-07-01 15:58:00 UTC (rev 279464)
+++ trunk/Source/WebKit/UIProcess/Cocoa/GroupActivities/WKGroupSession.swift	2021-07-01 16:34:58 UTC (rev 279465)
@@ -128,18 +128,25 @@
 public class WKGroupSessionObserver : NSObject {
     @objc public var newSessionCallback: ((WKGroupSessionWrapper) -> Void)?
 
-    private var observer = GroupSessionObserver(for: URLActivity.self)
-    private var cancellables: Set<AnyCancellable> = []
+    private var incomingSessionsTask: Task.Handle<Void, Never>?
 
     @objc public override init() {
         super.init()
 
-        observer
-            .sink { [unowned self] in self.recievedSession($0) }
-            .store(in: &cancellables)
+        incomingSessionsTask = detach { [weak self] in
+            for await newSession in URLActivity.self.sessions() {
+                DispatchQueue.main.async { [weak self] in
+                    self?.receivedSession(newSession)
+                }
+            }
+        }
     }
 
-    private func recievedSession(_ session: GroupSession<URLActivity>) {
+    deinit {
+        incomingSessionsTask?.cancel()
+    }
+
+    private func receivedSession(_ session: GroupSession<URLActivity>) {
         guard let callback = newSessionCallback else {
             return
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to