<p>What are futures? It's something to do with lazy evaluation.</p>

[{'answer_id': 80464, 'author': '0124816', 'author_id': 11521, 'author_profile': 'https://Stackoverflow.com/users/11521', 'pm_score': 2, 'selected': False, 'text': '<p>A Future encapsulates a deferred calculation, and is commonly used to shoehorn lazy evaluation into a non-lazy language. The first time a future is evaluated, the code required to evaluate it is run, and the future is replaced with the result. </p>\n\n<p>Since the future is replaced, subsequent evaluations do not execute the code again, and simply yield the result.</p>\n'}, {'answer_id': 80469, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 3, 'selected': False, 'text': '<p>When you create a future, a new background thread is started that begins calculating the real value. If you request the value of the future, it will block until the thread has finished calculating. This is very useful for when you need to generate some values in parallel and don\'t want to manually keep track of it all.</p>\n\n<p>See <a href="http://moonbase.rydia.net/software/lazy.rb/" rel="noreferrer">lazy.rb</a> for Ruby, or <a href="http://www.bluishcoder.co.nz/2006/07/scala-futures-and-lazy-evaluation.html" rel="noreferrer">Scala, futures, and lazy evaluation</a>.</p>\n\n<p>They can probably be implemented in any language with threads, though it would obviously be more difficult in a low-level language like C than in a high-level functional language.</p>\n'}, {'answer_id': 80519, 'author': 'Motti', 'author_id': 3848, 'author_profile': 'https://Stackoverflow.com/users/3848', 'pm_score': 3, 'selected': False, 'text': '<p>There is a <a href="http://en.wikipedia.org/wiki/Future_%28programming%29" rel="nofollow noreferrer">Wikipedia article</a> about futures. In short, it\'s a way to use a value that is not yet known. The value can then be calculated on demand (lazy evaluation) and, optionally, concurrently with the main calculation.</p>\n\n<p>C++ example follows.</p>\n\n<hr>\n\n<p>Say you want to calculate the sum of two numbers. You can either have the typical eager implementation:</p>\n\n<pre><code>int add(int i, int j) { return i + j; }\n// first calculate both Nth_prime results then pass them to add\nint sum = add(Nth_prime(4), Nth_prime(2)); \n</code></pre>\n\n<p>or you can use the futures way using C++11\'s <code>std::async</code>, which returns an <code>std::future</code>. In this case, the <code>add</code> function will only block if it tries to use a value that hasn\'t yet been computed (one can also create a purely lazy alternative).</p>\n\n<pre><code>int add(future&lt;int&gt; i, future&lt;int&gt; j) { return i.get() + j.get(); }\nint sum = add(async(launch::async, [](){ return Nth_prime(4); }),\n              async(launch::async, [](){ return Nth_prime(2); }));\n</code></pre>\n'}, {'answer_id': 80635, 'author': 'Robert Gould', 'author_id': 15124, 'author_profile': 'https://Stackoverflow.com/users/15124', 'pm_score': 3, 'selected': False, 'text': "<p>Everyone mentions futures for the purpose of lazy calculation. However another use that isn't as advertised is the use of Futures for IO in general. Especially they're useful for loading files and waiting on network data</p>\n"}, {'answer_id': 80729, 'author': 'Apocalisp', 'author_id': 3434, 'author_profile': 'https://Stackoverflow.com/users/3434', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Future_(programming)" rel="nofollow noreferrer">The Wiki Article</a> gives a good overview of Futures. The concept is generally used in concurrent systems, for scheduling computations over values that may or may not have been computed yet, and further, whose computation may or may not already be in progress.</p>\n\n<p>From the article:</p>\n\n<blockquote>\n  <p>A future is associated with a\n  specific thread that computes its\n  value. This computation may be started\n  either eagerly when the future is\n  created, or lazily when its value is\n  first needed.</p>\n</blockquote>\n\n<p>Not mentioned in the article, futures are a <a href="http://en.wikipedia.org/wiki/Monads_in_functional_programming" rel="nofollow noreferrer">Monad</a>, and so it is possible to project functions on future values into the monad to have them applied to the future value when it becomes available, yielding another future which in turn represents the result of that function.</p>\n'}, {'answer_id': 1287691, 'author': 'scope_creep', 'author_id': 89521, 'author_profile': 'https://Stackoverflow.com/users/89521', 'pm_score': 0, 'selected': False, 'text': "<p>Futures are also used in certain design patterns, particularly for real time patterns, for example, the ActiveObject pattern, which seperates method invocation from method execution. The future is setup to wait for the completed execution. I tend to see it when you need to move from a multithreaded enviroment to communicate with a single threaded environment. There may be instances where a piece of hardware doesn't have kernel support for threading, and futures are used in this instance. At first glance it not obvious how you would communicate, and surprisingly futures make it fairly simple.  I've got a bit of c# code. I'll dig it out and post it.  </p>\n"}, {'answer_id': 5548588, 'author': 'Felix', 'author_id': 238100, 'author_profile': 'https://Stackoverflow.com/users/238100', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://vigtig.it/blog/?p=73#more-73" rel="nofollow">This blog post</a> gives a <strong>very thorough</strong> explanation together with an example of how you could implement a future yourself. I really recommend it :)</p>\n'}]
['https://Stackoverflow.com/questions/80447', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']