@ -2154,7 +2154,7 @@ with <lock>: # Enters the block by calling acq
<bool> = <Future>.done() # Checks if the thread has finished executing.
<obj> = <Future>.result(timeout=None) # Waits for thread to finish and returns result.
<bool> = <Future>.cancel() # Cancels or returns False if running/finished.
<iter> = as_completed(<coll_of_Futures>) # Next() waits for next completed Future.
<iter> = as_completed(<coll_of_Futures>) # `next(<iter>)` returns next completed Future.
```
* **Map() and as\_completed() also accept 'timeout'. It causes futures.TimeoutError when next() is called/blocking. Map() times from original call and as_completed() from first call to next(). As\_completed() fails if next() is called too late, even if thread finished on time.**
* **Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.**
<pre><codeclass="python language-python hljs"><bool> = <Future>.done() <spanclass="hljs-comment"># Checks if the thread has finished executing.</span>
<obj> = <Future>.result(timeout=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
<bool> = <Future>.cancel() <spanclass="hljs-comment"># Cancels or returns False if running/finished.</span>
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Next() waits for next completed Future.</span>
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># `next(<iter>)` returns next completed Future.</span>
</code></pre>
<ul>
<li><strong>Map() and as_completed() also accept 'timeout'. It causes futures.TimeoutError when next() is called/blocking. Map() times from original call and as_completed() from first call to next(). As_completed() fails if next() is called too late, even if thread finished on time.</strong></li>
<pre><codeclass="python language-python hljs"><coro> = aio.gather(<coro/task>, ...) <spanclass="hljs-comment"># Schedules coros. Returns list of results on await.</span>
<iter> = aio.as_completed(<coros/tasks>) <spanclass="hljs-comment"># Iter of coros. All return next result when awaited.</span>
<iter> = aio.as_completed(<coros/tasks>) <spanclass="hljs-comment"># Iterator of coros. All return next result on await.</span>
</code></pre>
<div><h4id="runsaterminalgamewhereyoucontrolanasteriskthatmustavoidnumbers">Runs a terminal game where you control an asterisk that must avoid numbers:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> asyncio, collections, curses, curses.textpad, enum, random