Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions Sources/DistributedActors/ActorRef+Ask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ extension _ActorRef: ReceivesQuestions {
_ makeQuestion: @escaping (_ActorRef<Answer>) -> Question
) -> AskResponse<Answer> {
guard let system = self._system else {
return .completed(.failure(AskError.systemAlreadyShutDown))
return .completed(.failure(RemoteCallError.clusterAlreadyShutDown))
}

if system.isShuttingDown {
return .completed(.failure(AskError.systemAlreadyShutDown))
return .completed(.failure(RemoteCallError.clusterAlreadyShutDown))
}

do {
Expand Down Expand Up @@ -147,11 +147,6 @@ enum AskResponse<Value> {
case nioFuture(EventLoopFuture<Value>)
}

enum AskError: DistributedActorSystemError, Error {
case timedOut(TimeoutError)
case systemAlreadyShutDown
}

extension AskResponse {
/// Blocks and waits until there is a response or fails with an error.
@available(*, deprecated, message: "Blocking API will be removed in favor of async await")
Expand Down Expand Up @@ -203,7 +198,7 @@ extension AskResponse: _AsyncResult {
let eventLoop = nioFuture.eventLoop
let promise: EventLoopPromise<Value> = eventLoop.makePromise()
let timeoutTask = eventLoop.scheduleTask(in: timeout.toNIO) {
promise.fail(AskError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout)))
promise.fail(RemoteCallError.timedOut(TimeoutError(message: "\(type(of: self)) timed out after \(timeout.prettyDescription)", timeout: timeout)))
}
nioFuture.whenFailure {
timeoutTask.cancel()
Expand Down Expand Up @@ -283,7 +278,7 @@ internal enum AskActor {
Ask was initiated from function [\(function)] in [\(file):\(line)] and \
expected response of type [\(String(reflecting: ResponseType.self))].
"""
completable.fail(AskError.timedOut(TimeoutError(message: errorMessage, timeout: timeout)))
completable.fail(RemoteCallError.timedOut(TimeoutError(message: errorMessage, timeout: timeout)))

// FIXME: Hack to stop from subReceive. Should we allow this somehow?
// Maybe add a SubReceiveContext or similar?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ extension OpLogDistributedReceptionist {
try await peerReceptionistRef.ackOps(until: latestAppliedSeqNrFromPeer, by: self)
} catch {
switch error {
case AskError.systemAlreadyShutDown:
case RemoteCallError.clusterAlreadyShutDown:
// ignore silently; this often happens during tests when we terminate systems while interacting with them
()
default:
Expand Down
5 changes: 3 additions & 2 deletions Sources/DistributedActors/ClusterSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ extension ClusterSystem {
Err: Error
{
guard let shell = self._cluster else {
throw AskError.systemAlreadyShutDown
throw RemoteCallError.clusterAlreadyShutDown
}

let recipient = _ActorRef<InvocationMessage>(.remote(.init(shell: shell, address: actor.id._asRemote, system: self)))
Expand Down Expand Up @@ -1065,8 +1065,9 @@ internal struct LazyStart<Message: ActorMessage> {
}
}

enum RemoteCallError: Error {
enum RemoteCallError: DistributedActorSystemError, Error {
case clusterAlreadyShutDown
case timedOut(TimeoutError)
}

/// Allows for configuring of remote calls by setting task-local values around a remote call being made.
Expand Down
8 changes: 4 additions & 4 deletions Tests/DistributedActorsTests/ActorAskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ final class ActorAskTests: ActorSystemXCTestCase {
_ = try response.wait()
}

guard case AskError.timedOut = error else {
throw testKit.fail("Expected AskError.timedOut, got \(error)")
guard case RemoteCallError.timedOut = error else {
throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)")
}
}

Expand Down Expand Up @@ -197,8 +197,8 @@ final class ActorAskTests: ActorSystemXCTestCase {
try result.wait()
}

guard case AskError.timedOut = error else {
throw testKit.fail("Expected AskError.timedOut, got \(error)")
guard case RemoteCallError.timedOut = error else {
throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)")
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/DistributedActorsTests/ClusterSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ final class ClusterSystemTests: ActorSystemXCTestCase {
}
}

guard case AskError.timedOut(let timeoutError) = error else {
throw testKit.fail("Expected AskError.timedOut, got \(error)")
guard case RemoteCallError.timedOut(let timeoutError) = error else {
throw testKit.fail("Expected RemoteCallError.timedOut, got \(error)")
}
guard timeoutError.timeout == .seconds(1) else {
throw testKit.fail("Expected timeout to be 1 second but was \(timeoutError.timeout)")
Expand Down