title: How does concurrent.futures.as_completed work?
body: <p>I'm learning about python concurrency and I was introduced with the concept of futures. I read that <code>as_completed()</code> takes an iterable of futures and yields them as they are done.</p>
  
  <p>I want to know how it works internally. Is it yielding completed tasks (futures) immediately? A naive approach would be to iterate all futures and examine each and every future using <code>done()</code>, but this is inefficient. </p>
  
  <p>So what's the magic behind this function?</p>
  
  <p>Thanks!</p>