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 8909863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:32:32+00:00 2026-06-15T03:32:32+00:00

How can I use Akka Actor ask and maintain type safety? or avoid using

  • 0

How can I use Akka Actor ask and maintain type safety? or avoid using ask in favour of tells?

When calling ? or ask on an Akka Actor, a Future[Any] is returned and I have to do an explicit cast via future.mapTo[MyType].

I don’t like losing this type safety. If I use Futures directly (with no actors) I can explicitly return Future[MyType] and maintain type safety.

My specific use case involves an actor delegating it’s message to two child actors and then aggregating the results from those actors and returning that to the parent’s sender. My parent’s receive method looks similar to this approach in the Akka Docs:

http://doc.akka.io/docs/akka/2.0/scala/futures.html#For_Comprehensions

val f1 = actor1 ? msg
val f2 = actor2 ? msg

val f3 = for {
  a ← f1.mapTo[Int]
  b ← f2.mapTo[Int]
  c ← ask(actor3, (a + b)).mapTo[Int]
} yield c

Is there a better way to achieve my use case?

  • 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-06-15T03:32:33+00:00Added an answer on June 15, 2026 at 3:32 am

    Try typed actors. Basically they allow you to interact with an actor using strongly typed traits/interfaces rather than by exchanging messages. Behind the scenes Akka implements these interfaces with a dynamic proxy and does the asynchronous magic.

    Typed actor can return have methods with different, strongly typed return values (from documentation mentioned above):

    def squareDontCare(i: Int): Unit //fire-forget
    
    def square(i: Int): Future[Int] //non-blocking send-request-reply
    
    def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply
    
    def squareNow(i: Int): Int //blocking send-request-reply
    

    These method represents tell while the remaining ones are different flavours of ask.

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

Sidebar

Related Questions

can use anything in any order? does placing of <meta http-equiv=Content-Type content=text/html;charset=UTF-8> is important
We can use pair sequences to create heterogenous lists in Haskell: type a *:
Can wsgi be configured to use a specific python executable? When using the WSGIPythonHome
We can use a C# typeof keyword when we want to get Type instance
I can use .map(func) on any column in a df, like: df = DataFrame({'a':[1,2,3,4,5,6],
I've read akka documentation and can't produce clean understanding of thread interaction while using
can i use hibernate to login jsp page using (session) if i'm not using
I am using Akka for actor model programming with Scala, and in order to
I can use C-h c ( describe-key-briefly ) and type a key combination and
How can use the WebBrowser control in WPF to navigate using Search engine uri

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.