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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:34:11+00:00 2026-06-16T02:34:11+00:00

In Scala 2.10, along with the new Future / Promise API, they introduced a

  • 0

In Scala 2.10, along with the new Future/Promise API, they introduced a Duration and Deadline utilities (as described here). I looked around but couldn’t find anything that comes with the scala standard library, to do something like:

val deadline = 5 seconds fromNow
After(deadline){
  //do stuff
}

//or

val deadlineFuture: Future[Nothing] = (5 seconds fromNow).asFuture
deadlineFuture onComplete {
  //do stuff
}

Is there anything like that available that I’ve missed, or will I have to implement this kind of behavior myself?

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

    Not quite built in, but they provide just enough rope.

    The gist is to wait on an empty promise that must disappoint (i.e., time out).

    import scala.concurrent._
    import scala.concurrent.duration._
    import scala.util._
    import ExecutionContext.Implicits.global
    
    object Test extends App {
      val v = new SyncVar[Boolean]()
      val deadline = 5 seconds fromNow
      future(Await.ready(Promise().future, deadline.timeLeft)) onComplete { _ =>
        println("Bye, now.")
        v.put(true)
      }
      v.take()
      // or
      val w = new SyncVar[Boolean]()
      val dropdeadline = 5 seconds fromNow
      val p = Promise[Boolean]()
      p.future onComplete {_ =>
        println("Bye, now.")
        w.put(true)
      }
      Try(Await.ready(Promise().future, dropdeadline.timeLeft))
      p trySuccess true
      w.take()
      // rolling it
      implicit class Expiry(val d: Deadline) extends AnyVal {
        def expiring(f: =>Unit) {
          future(Await.ready(Promise().future, d.timeLeft)) onComplete { _ =>
            f
          }
        }
      }
      val x = new SyncVar[Boolean]()
      5 seconds fromNow expiring {
        println("That's all, folks.")
        x.put(true)
      }
      x.take() // wait for it
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was messing around with Scala 2.8 for fun and trying to define a
I'm new to Scala but I was wondering it it is possible to implement
Following along with chapters and examples in Scala for the Impatient, there's an exercise
I'm pretty new to Scala but I like to know what is the preferred
I'm really new to Scala, and I've come across an error I am unable
I am very new to Scala. I want to implement a generic matrix class
I'm experimenting with using jEdit as my main editor for writing Scala code. Along
The following code: var text = (new WebClient()).DownloadString(http://export.arxiv.org/api/query?search_query=au:Freidel_L*&start=0&max_results=20)); results in a variable text that
I'm new at using Play Framework 2.0 (I am using Scala) and have a
I am new to Scala but an experienced programmer trying to shed old habits

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.