title: How are Promises implemented in Javascript without threads
body: <p>Recently, I have been seeing the concept of Promises being implemented in AngularJS and JQuery.</p>
  <p>I have seen the implementation of a Futures in Java as in code below, however this requires concept of thread pools to be present in language/platform. However, there is no such threading concept in Javascript. How are Promises in Javascript implemented then ?</p>
  <pre class="lang-java prettyprint-override"><code>public class Futures1 {
  
      private static final ExecutorService pool = Executors
              .newFixedThreadPool(10);
  
      public static void main(String[] args) {
  
          Future&lt;String&gt; contentsFuture = null;
          try {
              contentsFuture = startDownloading(new URL(&quot;http://www.example.com&quot;));
          } catch (MalformedURLException e) {
              e.printStackTrace();
          }
          // other computation
          try {
              final String contents = contentsFuture.get();
          } catch (InterruptedException | ExecutionException e) {
              e.printStackTrace();
          }
  
      }
      
      public static Future&lt;String&gt; startDownloading(final URL url) {
          return pool.submit(new Callable&lt;String&gt;() {
              @Override
              public String call() throws Exception {
                  try (InputStream input = url.openStream()) {
                      return IOUtils.toString(input, StandardCharsets.UTF_8);
                  }
              }
          });
      }
  }
  </code></pre>