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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:49:49+00:00 2026-05-23T03:49:49+00:00

What’s the the connection between those Future-related class and traits in Scala, and why

  • 0

What’s the the connection between those Future-related class and traits in Scala, and why are they sprinkled over different packages?

I have found those:

abstract class scala.actors.Future
object         scala.actors.Futures
trait/object   scala.collection.parallel.FutureThreadPoolTasks
trait          scala.concurrent.FutureTaskRunner
trait          scala.parallel.Future    (the package consists of only this file...)

Do they significantly different things or is there another reason why they can’t be consolidated?

Is there a good example showing when one would use the one thing or the other?

Edit: Bounty for explaining what each of the classes/traits/objects does and how they justify their existance/how they are useful.

  • 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-23T03:49:49+00:00Added an answer on May 23, 2026 at 3:49 am

    scala.actors._

    abstract class Future

    First of all, lets see what the documentation says:

    A function of arity 0, returing a value of type T that, when applied, blocks the current actor (Actor.self) until the future’s value is available.

    And that is basically all there is. If you are communicating with an Actor from anywhere outside of another actor (which can receive asynchronous replies to messages simply with another message, using the sender reference) and you need the reply to a sent message, you have two choices:

    • Send a blocking message which waits until the Actor is done computing your result
    • Send a message using a method which returns a Future, and block on that Future only if you really need the value in question (which by then may have alreay been computed)

    So a Future is a placeholer for a value which does not yet exist, but probably will in the near future. The following is also interesting:

    A future can be queried to find out whether its value is already available without blocking [using “isSet”].

    This allows you to do whatever you want until the value you need has been computed/fetched, and you can periodically check if the value has become available.

    When digging a bit into the Scala library source code, I found out that Futures are actually just actors. Future itself is a an abstract class, which is extended by the private class FutureActor. This last class is the one that actually implements the Future-functionality.

    object Futures

    The object Futures is by far not as interesting, as it is merely a container for the “Methods that operate on futures”, the handy factory method future which asynchronously evaluates the passed block, returning a future representing the result. A small example would be this:

    import scala.actors.Futures
    val f = Futures.future {
        println("Start: inside block")
        val s = System.currentTimeMillis
        while(System.currentTimeMillis < (s + 1000)) {
            // Simulate computation
        }
        println("Start: end of block")
        42
    }
    println("After future")
    println(f())
    println("The end")
    

    Which should result in something like

    Start: inside block
    After future
    Start: end of block
    42
    The end
    

    This demonstrates that the future-call does not block the following code until you actually try to retrieve the value of the future (note that the output is non-deterministic. After future could also appear at the beginning of the output).

    scala.collection.parallel

    This packages is new to Scala 2.9.x and implements parallel counterparts for some of our favorite collections. These all start with Par:

    • ParIterable
    • ParSeq
    • ParSet
    • ParMap

    As you may have known or guessed already, these collections implement all possible operations in a parallel manner without you having to worry about it. A small demonstration:

    (1 to 10).par.map { b => print(b + " "); b * b }
    3 1 6 2 7 4 5 9 10 8
        # => (1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
    

    The result will always be the same, but the order in which the elements are processed is again non-deterministic. Also, if you are on a multicore system, you will probably experience a nice performance boost for larger collections.

    trait FutureThreadPoolTasks

    The FutureThreadPoolTasks trait extends the Tasks trait, so lets take a look at that one first. The comment above the trait says:

    A trait that declares task execution capabilities used by parallel collections.

    Judging from the other source comments and the methods found in the Tasks trait, a Task represents a unit of work which needs to be computed. Depending on wether or not a problem is divisible further and if there are more resources available, a Task can split up a Task further by creating more tasks.

    Now the FutureThreadPoolTasks trait itself is just a way to compute tasks, which uses the java.util.concurrent.Future class for its synchronization, that is, it does not use scala.actors.Future! From the source:

    An implementation of tasks objects based on the Java thread pooling API and synchronization using futures.

    object FutureThreadPoolTasks

    Once again not very spectacular, just a companion object containing a few (actually only three) utility methods which the FutureThreadPoolTasks trait uses.

    scala.concurrent

    The documentation on these classes is really bad and apparently there are very few if any (I didn’t find a single one) examples which demonstrate the usage of these classes. I will definitely try to gather more information on these and expand on this section as soon as I can!

    scala.parallel

    trait Future

    This seems to be a “Work in progess”, as the scala.parallel package only contains this trait. From what I can tell, this is going to be related to a Future implementation which does not use Actors, but that is just a guess. The signature of the trait is the following

    trait Future[@specialized +R] extends (() => R)
    

    I am not even going to try to explain the @specialized annotation or variances (the + before the generic R type), but the basic idea in this trait is that a Future is a function which, when executed, returns the value (and must therefor block if it has not been computed yet).

    Also, there are only two methods inside the trait itself, apply and isDone. My guess is that isDone, just like the scala.actors.Future.isSet, is supposed to be a non-blocking call to see if the value has been computed, and the apply method should be used to actually retrieve the value.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.