Questions tagged [future]

A placeholder for the result of a calculation before the calculation has completed. Used in concurrent programming. Questions about future events are off-topic on Stack Overflow.

A Wikipedia article on futures in concurrent programming.

A tutorial on concurrent programming in Java by Lars Vogel, including a section on futures and callables.

See also:

3834 questions
2
votes
1 answer

Changing map to pmap in my Clojure program leads to weird exception (ClassCastException)

As far as I know, pmap in Clojure works just like map, but it calculates results in parallel, using futures under the hood. So it should "just work" with a function and a sequence, if map works with them. (Unless there are evil side effects that…
Display Name
  • 8,022
  • 3
  • 31
  • 66
2
votes
3 answers

How to add callbacks to Future in Scala?

I saw an example here: val fut = Future { ... // my body function } // my body function starts here fut onComplete { ... // my callback } Looks like I may add the callback after the completion of my body function. Is it still invoked ? Anyway, I…
Michael
  • 41,026
  • 70
  • 193
  • 341
2
votes
0 answers

Memory usage with future and containers in Qt / MinGW

Consider the following test code: #include #include #include #include using std::vector; using std::array; using std::cout; using std::endl; typedef unsigned int uint; double TestFutures() { return…
DrD
  • 419
  • 4
  • 14
2
votes
0 answers

javascript dom using futures

the dom standard now apparently includes futures from what I can tell from the doc, this seems to be a different flavor that what most people advertise as futures - in particular there seems to be no join function which is at the heart of other…
cc young
  • 18,939
  • 31
  • 90
  • 148
2
votes
2 answers

Scala check if Future[Seq[String]] isEmpty

I would like to check if a Future[Seq[String]] is Empty and I am using if(!Future.sequence(sortSeq).isEmpty){ //doSomething } but it throws me error ?
princess of persia
  • 2,222
  • 4
  • 26
  • 43
2
votes
1 answer

Convert Future[Seq[(String, String)]] to Future[Seq[(String)]]

I am trying to convert Future[Seq[(String, String)]] to Future[Seq[(String)]] using the following: sortedSeq.map(_._2) so sortedSeq is of type Future[Seq[(String, String)]] but I keep getting the error : value _2 is not a member of Seq[(String,…
princess of persia
  • 2,222
  • 4
  • 26
  • 43
2
votes
1 answer

Is it a good idea to use Python futures for tasks without results?

The question came up, when I started implementing asynchronous set and get operations on an object using the concurrent.futures module like this: import time from concurrent.futures import ThreadPoolExecutor executor =…
matthias
  • 2,161
  • 15
  • 22
2
votes
1 answer

akka firstCompletedOf, identify message sender

I'm using Scala 2.10 / Akka 2.1 / Play 2.1, and I have a question about firstCompletedOf. How do I identify the sender of the result in the firstCompletedOf body? Look at the following code: val futureString: Future[String] =…
ticofab
  • 7,551
  • 13
  • 49
  • 90
2
votes
4 answers

CPS library for nice dataflow with Scala 2.10 futures

I am looking for a light weight library that allows me, instead of writing: val future1 = process1() future1.onSuccess { process2() } the following: val future1 = process1() future1.await() process2() without blocking the thread (so not:…
0__
  • 66,707
  • 21
  • 171
  • 266
2
votes
3 answers

Interrupting a thread prior to calling Future.get()

I'm trying to write an integration test that causes an InterruptedException to be raised from the production code: @Test public void test() { productionObject = new ProductionObject( …
hertzsprung
  • 9,445
  • 4
  • 42
  • 77
2
votes
1 answer

Futures, TimeoutException, and Callables with finally blocks

Will a finally block withing a thread be called if the Callable is canceled via future.get(timeout, TimeUnit.SECONDS)? class MyCallable implements Callable>{ public Future call(){ Connection conn = pool.getConnection(); …
user1980584
  • 61
  • 1
  • 4
2
votes
2 answers

direct use of Futures in Akka

I am not able to create a Future as explained here. It says you can create a Future directly using the following code: import akka.dispatch.Await import akka.dispatch.Future import akka.util.duration._ val future = Future { "Hello" +…
tgr
  • 3,557
  • 4
  • 33
  • 63
2
votes
1 answer

Scala Actors: Returning a Future of a type other than Any.

I am working my way through a book on Scala Actors, and I am running into a bit of a syntactical hangup. In practice, I tend to assign my variables and function definitions as such: val v: String = "blahblahblah" def f(n: Int): Int = n+1 including…
Chris Grimm
  • 771
  • 6
  • 15
2
votes
2 answers

Interrupt a thread in java

I found this solution to know if a thread has been interrupted. public class OurThread extends Thread(){ private volatile boolean stop = false; public void run(){ while (!stop) { //Do your actions } } …
2
votes
2 answers

Quicksort using Future ends up in a deadlock

I have written a quicksort (method quicksortF()) that uses a Scala's Future to let the recursive sorting of the partitions be done concurrently. I also have implemented a regular quicksort (method quicksort()). Unfortunately, the Future version ends…
1 2 3
99
100