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
371
votes
9 answers

What's the difference between a Future and a Promise?

What's the difference between Future and Promise? They both act like a placeholder for future results, but where is the main difference?
Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
322
votes
5 answers

What are the differences between Deferred, Promise and Future in JavaScript?

What are the differences between Deferreds, Promises and Futures? Is there a generally approved theory behind all these three?
Tower
  • 98,741
  • 129
  • 357
  • 507
218
votes
14 answers

Waiting on a list of Future

I have a method which returns a List of futures List> futures = getFutures(); Now I want to wait until either all futures are done processing successfully or any of the tasks whose output is returned by a future throws an exception. Even…
user93796
  • 18,749
  • 31
  • 94
  • 150
164
votes
1 answer

Futures vs. Promises

I'm confusing myself with difference between a future and a promise. Obviously, they have different methods and stuff, but what is the actual use case? Is it?: when I'm managing some async task, I use future to get the value "in future" when I'm…
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
135
votes
8 answers

Transform Java Future into a CompletableFuture

Java 8 introduces CompletableFuture, a new implementation of Future that is composable (includes a bunch of thenXxx methods). I'd like to use this exclusively, but many of the libraries I want to use return only non-composable Future instances. Is…
Dan Midwood
  • 18,694
  • 7
  • 33
  • 32
126
votes
6 answers

Scala: List[Future] to Future[List] disregarding failed futures

I'm looking for a way to convert an arbitrary length list of Futures to a Future of List. I'm using Playframework, so ultimately, what I really want is a Future[Result], but to make things simpler, let's just say Future[List[Int]] The normal way to…
Joe
  • 1,723
  • 2
  • 14
  • 16
113
votes
6 answers

How to create a completed future in java

What is the best way to construct a completed future in Java? I have implemented my own CompletedFuture below, but was hoping something like this that already exists. public class CompletedFuture implements Future { private final T…
Jake Walsh
  • 3,669
  • 5
  • 22
  • 28
113
votes
4 answers

Get the status of a std::future

Is it possible to check if a std::future has finished or not? As far as I can tell the only way to do it would be to call wait_for with a zero duration and check if the status is ready or not, but is there a better way?
David Brown
  • 13,336
  • 4
  • 38
  • 55
110
votes
4 answers

Dartlang wait more than one future

I want to do something after a lot of future functions are done, but I do not know how to write the code in dart? the code is like this: for (var d in data) { d.loadData().then() } // when all loaded // do something here but I don't want to wait…
bitnick
  • 1,903
  • 3
  • 16
  • 22
105
votes
10 answers

Pass multiple parameters to concurrent.futures.Executor.map?

The concurrent.futures.Executor.map takes a variable number of iterables from which the function given is called. How should I call it if I have a generator that produces tuples that are normally unpacked in place? The following doesn't work because…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
103
votes
3 answers

When should I use a FutureBuilder?

I was wondering when I should use the future builder. For example, if I want to make an http request and show the results in a list view, as soon as you open the view, should I have to use the future builder or just build a ListViewBuilder like: new…
Little Monkey
  • 5,395
  • 14
  • 45
  • 83
101
votes
6 answers

Promise equivalent in C#

In Scala there is a Promise class that could be used to complete a Future manually. I am looking for an alternative in C#. I am writing a test and I want it to look it similar to this: // var MyResult has a field `Header` var promise = new…
eddyP23
  • 6,420
  • 7
  • 49
  • 87
100
votes
5 answers

Combine awaitables like Promise.all

In asynchronous JavaScript, it is easy to run tasks in parallel and wait for all of them to complete using Promise.all: async function bar(i) { console.log('started', i); await delay(1000); console.log('finished', i); } async function foo()…
Tamas Hegedus
  • 28,755
  • 12
  • 63
  • 97
95
votes
6 answers

Dart, how to create a future to return in your own functions?

is it possible to create your own futures in Dart to return from your methods, or must you always return a built in future return from one of the dart async libraries methods? I want to define a function which always returns a Future>…
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112
93
votes
5 answers

Why should I use std::async?

I'm trying to explore all the options of the new C++11 standard in depth, while using std::async and reading its definition, I noticed 2 things, at least under linux with gcc 4.8.1 : it's called async, but it got a really "sequential behaviour",…
user2485710
  • 9,451
  • 13
  • 58
  • 102
1
2 3
99 100