From 8d679ece8e6a48933b59d54b222ce22c148ba918 Mon Sep 17 00:00:00 2001 From: Muukii Date: Wed, 18 Dec 2024 14:16:25 +0900 Subject: [PATCH] Patch --- .../Components/Tools/NamedDisplayCellNodeBase.swift | 12 ++++++------ Sources/Components/Tools/NamedDisplayNodeBase.swift | 13 +++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Sources/Components/Tools/NamedDisplayCellNodeBase.swift b/Sources/Components/Tools/NamedDisplayCellNodeBase.swift index 2b67497..be728be 100644 --- a/Sources/Components/Tools/NamedDisplayCellNodeBase.swift +++ b/Sources/Components/Tools/NamedDisplayCellNodeBase.swift @@ -21,8 +21,6 @@ import AsyncDisplayKit -fileprivate let queue = DispatchQueue.global() - /// An object from Abstract base class /// /// This object sets name of object for accessibilityIdentifier @@ -32,16 +30,17 @@ fileprivate let queue = DispatchQueue.global() /// - Author: TetureSwiftSupport open class NamedDisplayCellNodeBase: ASCellNode { - private var __actionHandlers: [(NamedDisplayCellNodeBase, DisplayNodeAction) -> Void] = [] + private var __actionHandlers: [@MainActor (NamedDisplayCellNodeBase, DisplayNodeAction) -> Void] = [] @MainActor open override func didLoad() { super.didLoad() #if DEBUG - queue.async { [weak self] in + Task.detached { [weak self] in guard let self = self else { return } let typeName = _typeName(type(of: self)) - DispatchQueue.main.async { + + Task { @MainActor in guard self.accessibilityIdentifier == nil else { return } self.accessibilityIdentifier = typeName } @@ -56,7 +55,7 @@ open class NamedDisplayCellNodeBase: ASCellNode { - Warning: Non-atomic */ @discardableResult - public func addNodeActionHandler(_ handler: @escaping (Self, DisplayNodeAction) -> Void) -> Self { + public func addNodeActionHandler(_ handler: @escaping @MainActor (Self, DisplayNodeAction) -> Void) -> Self { __actionHandlers.append { node, action in guard let node = node as? Self else { assertionFailure() @@ -68,6 +67,7 @@ open class NamedDisplayCellNodeBase: ASCellNode { return self } + @MainActor private func propagate(action: DisplayNodeAction) { for handler in __actionHandlers { handler(self, action) diff --git a/Sources/Components/Tools/NamedDisplayNodeBase.swift b/Sources/Components/Tools/NamedDisplayNodeBase.swift index 535c04f..f2b2f40 100644 --- a/Sources/Components/Tools/NamedDisplayNodeBase.swift +++ b/Sources/Components/Tools/NamedDisplayNodeBase.swift @@ -21,8 +21,6 @@ import AsyncDisplayKit -fileprivate let queue = DispatchQueue.global() - public enum DisplayNodeAction { case didLoad } @@ -42,10 +40,10 @@ open class NamedDisplayNodeBase: ASDisplayNode { open override func didLoad() { super.didLoad() #if DEBUG - queue.async { [weak self] in + Task.detached { [weak self] in guard let self = self else { return } let typeName = _typeName(type(of: self)) - DispatchQueue.main.async { + Task { @MainActor in guard self.accessibilityIdentifier == nil else { return } self.accessibilityIdentifier = typeName } @@ -71,7 +69,6 @@ open class NamedDisplayNodeBase: ASDisplayNode { return self } - @preconcurrency @MainActor private func propagate(action: DisplayNodeAction) { for handler in __actionHandlers { @@ -96,10 +93,10 @@ open class NamedDisplayControlNodeBase: ASControlNode { open override func didLoad() { super.didLoad() #if DEBUG - queue.async { [weak self] in + Task.detached { [weak self] in guard let self = self else { return } let typeName = _typeName(type(of: self)) - DispatchQueue.main.async { + Task { @MainActor in guard self.accessibilityIdentifier == nil else { return } self.accessibilityIdentifier = typeName } @@ -113,7 +110,7 @@ open class NamedDisplayControlNodeBase: ASControlNode { - Warning: Non-atomic */ @discardableResult - public func addNodeActionHandler(_ handler: @escaping (Self, DisplayNodeAction) -> Void) -> Self { + public func addNodeActionHandler(_ handler: @escaping @MainActor (Self, DisplayNodeAction) -> Void) -> Self { __actionHandlers.append { node, action in guard let node = node as? Self else { assertionFailure()