Skip to content

Commit

Permalink
Update to use mainActorFactory API
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfol committed Jul 20, 2024
1 parent 2bd07f8 commit 3508b25
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions Tests/KnitTests/MainActorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomGlobalActorClass, Never>.self,
factory: { resolver in
MainActor.assumeIsolated {
let mainClassA = resolver.resolve(MainClassA.self)!

return Future<CustomGlobalActorClass, Never>() { promise in
let customGlobalActorClass = await CustomGlobalActorClass(
mainClassA: mainClassA
)
promise(.success(customGlobalActorClass))
}
mainActorFactory: { @MainActor resolver in
let mainClassA = resolver.resolve(MainClassA.self)!

return Future<CustomGlobalActorClass, Never>() { promise in
let customGlobalActorClass = await CustomGlobalActorClass(
mainClassA: mainClassA
)
promise(.success(customGlobalActorClass))
}
}
)

container.register(
Future<AsyncInitClass, Never>.self,
factory: { resolver in
MainActor.assumeIsolated {
return Future<AsyncInitClass, Never>() { promise in
promise(.success(await AsyncInitClass()))
}
mainActorFactory: { @MainActor resolver in
return Future<AsyncInitClass, Never>() { 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<CustomGlobalActorClass, Never>.self)!
let asyncInitClass = resolver.resolve(Future<AsyncInitClass, Never>.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<CustomGlobalActorClass, Never>.self)!
let asyncInitClass = resolver.resolve(Future<AsyncInitClass, Never>.self)!
return FinalConsumer(
actorA: actorA,
mainClassA: mainClassA,
customGlobalActorClass: customGlobalActorClass,
asyncInitClass: asyncInitClass
)
}
)

Expand Down

0 comments on commit 3508b25

Please sign in to comment.