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

  • Home
  • SEARCH
  • 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 6584493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:32:38+00:00 2026-05-25T16:32:38+00:00

I have a simple Actor that queries a database using ScalaQuery, which I’ve mocked

  • 0

I have a simple Actor that queries a database using ScalaQuery, which I’ve mocked for a test of a client using it.

What I want is for the (mock) Actor to reply with Some(MyObject) if the ID matches up, and None otherwise. However, I can’t figure out how to make this work. Here’s the code I have so far:

def receive = {
  case FetchSomething(someId) => {
    if (someId == 1234) self.channel ! someObject
    else self.channel ! None
  }
}

However, instead of returning None in the client code, it returns Some(None) – which, of course, confuses my client. How I want the client to work is something like this:

val object = persister !! FetchSomething(1337) match {
    case myObject: Some[MyObject] => myObject
    case _ => None
}

(of course, the above may just be wrong – instead of Some, it could be Option)

How can I achieve this? Perhaps more specific, how can I send a None back through self.channel so when matching it, it’s None and not Some(None)?

  • 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-25T16:32:38+00:00Added an answer on May 25, 2026 at 4:32 pm

    The fault is in the client, which misinterpret the reply, not following AKKA protocol. From the Akka documentation :

    The !! method returns an Option[Any] which will be either Some(result)
    if returning successfully, or None if the call timed out.

    So if reply is None, client Some(None). If reply is Some(12) you get Some(Some(12)). If client receives None, it should not means the actor replied None, it means the actor did not reply.

    This is AKKA protocol, and it means client should process reply with

    case Some(answer) => process answer
    case None => actor did not reply
    

    Then if your actor happens to reply with an Option[Something], that is your protocol, which is another layer:

    case Some(answer) => /* your protocol */ answer match { 
      case Some(actualValue) => reply had actualValue
      case None => None was the reply
    }
    case None => actor did not reply
    

    Which of course, you can also write

    case Some(Some(actualValue)) => 
    case Some(None) => 
    case None => 
    

    A side note, do not match with x: Some[A] (do not give the type parameter when matching on a generic type). It does not work, it will not verify that you have a Some[Something], but not that Something is A (see type erasure, the compiler gives a warning). You want to match with case Some(x: A) which gives you the content of the Some in x, what you normally want. If you actually want the Some rather than its content, case s @ Some(x: A) will bind s to the Some instance, x to its content. Use _ instead of x if you are not interested in it.

    If it is known that the type inside the option is A, then do not mention it, just write
    case Some(x), case s: Some(_)

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

Sidebar

Related Questions

I have simple map-reduce type algorithm, which I want to implement in python and
In Scala, if I have a simple class as follows: val calc = actor
I have simple win service, that executes few tasks periodically. How should I pass
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package in which On Error event handler I have created
I have an enumeration that I want to use in pattern matches in an
I have simple Perl/CGI scripts based web server which is mainly used to display
I have simple template that's html mostly and then pulls some stuff out of
Simple one guys. I have an XML parsed using simplexml_load_file(). The following code: <?php
I have simple user registration form. In which i am puting city as a

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.