@@ -2,7 +2,7 @@ import Foundation
22import Testing
33@testable import AsyncMonitor
44
5- @ MainActor class AsyncMonitorTests {
5+ class AsyncMonitorTests {
66 let center = NotificationCenter ( )
77 let name = Notification . Name ( " a random notification " )
88
@@ -24,18 +24,18 @@ import Testing
2424 subject = center. notifications ( named: name) . map ( \. name) . monitor { receivedName in
2525 Issue . record ( " Called for irrelevant notification \( receivedName) " )
2626 }
27- Task {
27+ Task { [ center ] in
2828 center. post ( name: Notification . Name ( " something else " ) , object: nil )
2929 }
3030 try await Task . sleep ( for: . milliseconds( 10 ) )
3131 }
3232
33- @Test func stopsCallingBlockWhenDeallocated( ) async throws {
33+ @Test @ MainActor func stopsCallingBlockWhenDeallocated( ) async throws {
3434 subject = center. notifications ( named: name) . map ( \. name) . monitor { _ in
3535 Issue . record ( " Called after deallocation " )
3636 }
3737
38- Task {
38+ Task { @ MainActor in
3939 subject = nil
4040 center. post ( name: name, object: nil )
4141 }
@@ -48,7 +48,7 @@ import Testing
4848
4949 private var cancellable : ( any AsyncCancellable ) ?
5050
51- @ MainActor init ( center: NotificationCenter , deinitHook: @escaping ( ) -> Void ) {
51+ init ( center: NotificationCenter , deinitHook: @escaping ( ) -> Void ) {
5252 self . deinitHook = deinitHook
5353 let name = Notification . Name ( " irrelevant name " )
5454 cancellable = center. notifications ( named: name) . map ( \. name)
@@ -78,7 +78,7 @@ import Testing
7878 Issue . record ( " Called after context was deallocated " )
7979 }
8080 context = nil
81- Task {
81+ Task { [ center , name ] in
8282 center. post ( name: name, object: nil )
8383 }
8484 try await Task . sleep ( for: . milliseconds( 10 ) )
0 commit comments