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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:10:49+00:00 2026-06-12T02:10:49+00:00

Is there a way in Scala to execute something in a loop without blocking

  • 0

Is there a way in Scala to execute something in a loop without blocking the entire flow?

I have the following code to transmit something in Actor model

All actors send something to other actors:

def some_method
  loop {
  // Transmit something
  Thread.sleep(100)
}

I also have some code to receive what other actors send. But the flow is not coming out of the loop. It sleeps and continues without coming out of the loop. Thus, all actors keep sending but nobody receives. How can I fix this?

  • 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-12T02:10:51+00:00Added an answer on June 12, 2026 at 2:10 am

    If I understand you correctly, you want the transmission to occur every 100ms, but you don’t want to create another Thread for that (and a Thread.sleep inside an actor may indeed block the flow).
    You can use reactWithin:

    import java.util.Date
    import math.max
    
    def some_method = {
        var last_transmission_time = 0
        loop {
            val current_time = (new Date).getTime
            reactWithin(max(0, last_transmission_time + 100 - current_time)) {
                // actor reaction cases
    
                case TIMEOUT => {
                    // Transmit something
                    last_transmission_time = (new Date).getTime
                }
            }
        }
    }
    

    The last_transmission_time saves the last time a transmission was done.
    The reaction timeout is calculated so that a TIMEOUT will occur when the current time is the last-transmission-time + 100ms.

    If a timeout occured it means over 100ms passed since the last transmission, so another transmission should be called.

    If the reaction cases themselves may take a lot of time, then I don’t see any simple solution but creating another thread.

    I didn’t try the code because I’m not sure that I fully understand your problem.

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

Sidebar

Related Questions

Is there a way to launch the Scala shell and automatically execute the :load
is there any way I can achieve the following in scala with new Car()
Is there a way to execute a scala script from Eclipse with scala plugin?
As far as I understand it, there is no way in Scala to have
is there a way in Scala to sort an array of tuples using and
Is there a standard way of invoking the scala REPL from a gradle task?
Is there a good scala-esque (I guess I mean functional) way of recursively listing
Is there way to copy a file into Plone with WebDAV and have Plone
I was wondering if there was a way to execute very simple tasks on
Is there any way to execute a scalar-valued function from within a Derived Column

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.