Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7368201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:38:08+00:00 2026-05-29T03:38:08+00:00

As I understand it, an actor can be sent a message fire and forget

  • 0

As I understand it, an actor can be sent a message “fire and forget” style with the ! operator, or “Send-And-Receive-Future” style with the ? operator. An actor that is passed a message via ? must call a self.reply or the sender will receive a timeout exception. On the other hand, an actor that is passed a message via ! cannot have self.reply if the message is not being passed from another actor.

My question is, is the Actor supposed to know at compile time whether it will be invoked with ! or ? ??? Or if the necessity of self.reply can be determined at runtime, how can this be determined? Perhaps self.tryReply is involved, but the akka documentation seems to imply that a failed attempt to reply is an error case, whereas if the sender is not an actor, it is not really an error to fail to reply if the message is passed with !

Edit:

Here’s some code:

package akTest

import akka.actor.Actor

object Main1 {
  val worker = Actor.actorOf[ak].start()

  def main(args: Array[String]) {
    val resp = worker ? "Hi"
    resp.get
    println(resp)
  }
}

class ak extends Actor {
  def receive = {
    case msg:String  => {
      val response = "Received: " + msg
      println(response)
      response
    }
  }
}

This gets
Exception in thread "main" akka.dispatch.FutureTimeoutException: Futures timed out after [4995] milliseconds

So I add a self.reply to the actor:

class ak extends Actor {
  def receive = {
    case msg:String  => {
      val response = "Received: " + msg
      println(response)
      self.reply(response)
      response
    }
  }
}

This change fixes the timeout error. But now if I have a Main2 which sends a fire and forget message:

object Main2 {
  val worker = Actor.actorOf[ak].start()

  def main(args: Array[String]) {
    val resp = worker ! "Hi"
    println(resp)
  }
}

, a new error is produced: [ERROR] [2/1/12 2:04 PM] [akka:event-driven:dispatcher:global-1] [LocalActorRef]
No sender in scope, can't reply.

How can I write my actor to eliminate the coupling between its manner of response and the sender’s method of invoking? I don’t want to have 1 version of the actor for ! and a second version of the actor for ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:38:09+00:00Added an answer on May 29, 2026 at 3:38 am

    if senderFuture.isDefined then you have a future to reply to

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an actor to send a message every minute. How do I best
I understand that CGAffineTransformMakeRotation can rotate an image, and CGAffineTransformMakeTranslation translates an image. I
I understand that repr() 's purpose is to return a string, that can be
I understand that a const pointer can be declared a couple ways: const int
understand that in App.Xaml.cs, I can create global variable and properties. How do I
I understand how I can change the dns settings for my domains by editing
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that there are several ways to blend XNA and WPF within the
I understand that they are both supposed to be small, but what are the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.