Make most of MainThreadOperation @MainActor.

This commit is contained in:
Brent Simmons
2024-03-24 21:52:30 -07:00
parent cda4c9eb29
commit dbee19e169
2 changed files with 19 additions and 15 deletions

View File

@@ -18,12 +18,12 @@ import Foundation
public protocol MainThreadOperation: AnyObject {
// These three properties are set by MainThreadOperationQueue. Dont set them.
var isCanceled: Bool { get set } // Check this at appropriate times in case the operation has been canceled.
var id: Int? { get set }
var operationDelegate: MainThreadOperationDelegate? { get set } // Make this weak.
@MainActor var isCanceled: Bool { get set } // Check this at appropriate times in case the operation has been canceled.
@MainActor var id: Int? { get set }
@MainActor var operationDelegate: MainThreadOperationDelegate? { get set } // Make this weak.
/// Name may be useful for debugging. Unused otherwise.
var name: String? { get set }
@MainActor var name: String? { get set }
typealias MainThreadOperationCompletionBlock = (MainThreadOperation) -> Void
@@ -50,7 +50,7 @@ public protocol MainThreadOperation: AnyObject {
/// When this is called, you dont need to check isCanceled:
/// its guaranteed to not be canceled. However, if you run code
/// in another thread, you should check isCanceled in that code.
func run()
@MainActor func run()
/// Cancel this operation.
///
@@ -59,7 +59,7 @@ public protocol MainThreadOperation: AnyObject {
///
/// This function has a default implementation. Its super-rare
/// to need to provide your own.
func cancel()
@MainActor func cancel()
/// Make this operation dependent on an other operation.
///
@@ -70,7 +70,7 @@ public protocol MainThreadOperation: AnyObject {
///
/// This function has a default implementation. Its super-rare
/// to need to provide your own.
func addDependency(_ parentOperation: MainThreadOperation)
@MainActor func addDependency(_ parentOperation: MainThreadOperation)
}
public extension MainThreadOperation {