Moving the timeout so that it isn't calculated unless the actor is running

This commit is contained in:
Viktor Klang 2011-06-15 17:14:57 +02:00
parent df316b98de
commit 00e8fd79cb

View file

@ -1183,9 +1183,10 @@ trait ScalaActorRef extends ActorRefShared with ForwardableChannel { ref: ActorR
* Sends a message asynchronously, returning a future which may eventually hold the reply.
*/
def ?(message: Any, timeout: Actor.Timeout = Actor.noTimeoutGiven)(implicit channel: UntypedChannel = NullChannel, implicitTimeout: Actor.Timeout = Actor.defaultTimeout): Future[Any] = {
val realTimeout = if (timeout eq Actor.noTimeoutGiven) implicitTimeout else timeout
if (isRunning) postMessageToMailboxAndCreateFutureResultWithTimeout(message, realTimeout.duration.toMillis, channel)
else throw new ActorInitializationException(
if (isRunning) {
val realTimeout = if (timeout eq Actor.noTimeoutGiven) implicitTimeout else timeout
postMessageToMailboxAndCreateFutureResultWithTimeout(message, realTimeout.duration.toMillis, channel)
} else throw new ActorInitializationException(
"Actor has not been started, you need to invoke 'actor.start()' before using it")
}