From 3508b25af41af173a26db186ff4076f074f2ad87 Mon Sep 17 00:00:00 2001 From: Brad Fol Date: Fri, 19 Jul 2024 17:20:54 -0700 Subject: [PATCH] Update to use `mainActorFactory` API --- Tests/KnitTests/MainActorTests.swift | 62 ++++++++++++---------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/Tests/KnitTests/MainActorTests.swift b/Tests/KnitTests/MainActorTests.swift index 7939e26..8451840 100644 --- a/Tests/KnitTests/MainActorTests.swift +++ b/Tests/KnitTests/MainActorTests.swift @@ -97,64 +97,54 @@ private class TestAssembly: Assembly { container.register( ActorA.self, - factory: { resolver in - MainActor.assumeIsolated { - return ActorA() - } + mainActorFactory: { @MainActor resolver in + ActorA() } ) container.register( MainClassA.self, - factory: { resolver in - MainActor.assumeIsolated { - return MainClassA() - } + mainActorFactory: { @MainActor resolver in + MainClassA() } ) container.register( Future.self, - factory: { resolver in - MainActor.assumeIsolated { - let mainClassA = resolver.resolve(MainClassA.self)! - - return Future() { promise in - let customGlobalActorClass = await CustomGlobalActorClass( - mainClassA: mainClassA - ) - promise(.success(customGlobalActorClass)) - } + mainActorFactory: { @MainActor resolver in + let mainClassA = resolver.resolve(MainClassA.self)! + + return Future() { promise in + let customGlobalActorClass = await CustomGlobalActorClass( + mainClassA: mainClassA + ) + promise(.success(customGlobalActorClass)) } } ) container.register( Future.self, - factory: { resolver in - MainActor.assumeIsolated { - return Future() { promise in - promise(.success(await AsyncInitClass())) - } + mainActorFactory: { @MainActor resolver in + return Future() { promise in + promise(.success(await AsyncInitClass())) } } ) container.register( FinalConsumer.self, - factory: { resolver in - MainActor.assumeIsolated { - let actorA = resolver.resolve(ActorA.self)! - let mainClassA = resolver.resolve(MainClassA.self)! - let customGlobalActorClass = resolver.resolve(Future.self)! - let asyncInitClass = resolver.resolve(Future.self)! - return FinalConsumer( - actorA: actorA, - mainClassA: mainClassA, - customGlobalActorClass: customGlobalActorClass, - asyncInitClass: asyncInitClass - ) - } + mainActorFactory: { @MainActor resolver in + let actorA = resolver.resolve(ActorA.self)! + let mainClassA = resolver.resolve(MainClassA.self)! + let customGlobalActorClass = resolver.resolve(Future.self)! + let asyncInitClass = resolver.resolve(Future.self)! + return FinalConsumer( + actorA: actorA, + mainClassA: mainClassA, + customGlobalActorClass: customGlobalActorClass, + asyncInitClass: asyncInitClass + ) } )