title: Asynchronous step execution with cucumber-jvm
body: <p>Consider the following cucumber scenario:-</p>
  
  <pre><code>Scenario: Test payment
   Given I login to terminal
   When POS token is generated asynchronously
   Then user generates mobile token
   And payment is successful
  </code></pre>
  
  <p>The step "POS token is generated asynchronously" needs to execute asynchronously and should not block the execution of downstream steps after it. I was able to get it done with FutureTask in Java. However in case of failures I am not able to assert the failures. Below is the code snippet </p>
  
  <pre><code>@When("^POS token is generated asynchronously$")
  public void gs_Consumer() throws Throwable {
  
      HashMap&lt;String, Object&gt; m = DataContainer.getDataMap();
  
      ExecutorService executor = Executors.newFixedThreadPool(2);
      FutureTask&lt;Object&gt; futureTask1 = null;
  
      futureTask1 = new FutureTask&lt;Object&gt;(new Callable&lt;Object&gt;() {
  
          public Object call() throws Exception {
  
              DataContainer.setDataMap(m);
  
              try {
                  retrieve_consumer_information();
              } catch (Throwable e) {
                  DataContainer.getDataMap().put("exception", e);
                  throw new Exception(e);
              }
              return null;
          }
      });
  
      executor.execute(futureTask1);
  
      DataContainer.getDataMap().put("response", futureTask1);
      // Shutdown the ExecutorService
      executor.shutdown();
  }
  </code></pre>
  
  <p>Then I get the response in the After method since I cannot do a futureTask1.get() inside this method as it will block the execution from executing the other downstream steps. </p>
  
  <pre><code>public void afterAsynchMethod() {
  
       try {
          ((FutureTask&lt;Object&gt;) DataContainer.getDataMap().get("response")).get();
      } catch (InterruptedException | ExecutionException e) {
          // TODO Auto-generated catch block
          Assert.fail(e.getMessage());
      }
  
  }
  </code></pre>
  
  <p>Now if the exception happens in the After method the scenario still is not reflected as a failed scenario. How do I fail the scenario in this case or any other ways of doing this?</p>