ask
open suspend override fun <R : ActorProtocol.Response, M : ActorProtocol.Message<R>> ask(msg: M, timeout: Duration): Result<R>
Sends a message to the target actor and waits for a response within a specified timeout.
This function ensures that the response corresponds to the sent request. If the response is successfully received and matches the expected type, it returns the result. Otherwise, it handles failure scenarios, such as unexpected response types or exceptions.
Return
A Result containing the successfully received response of type R, or a failure if an error occurs during communication, response processing, or timeout.
Parameters
msg
The message to be sent to the target actor. Must implement ActorProtocol.Message with a corresponding response type.
timeout
The maximum duration to wait for a response before timing out.