title: GraalVM JavaScript in Java - How to identify an async method
body: <p>Consider we have the following JS code:</p>
  <pre><code>    async function helloAsync(){
          return &quot;Hello&quot;;
      }
  
      function hello(){
          return &quot;Hello&quot;;
      }
  </code></pre>
  <p>In Java, you can load this code into a GraalVM context object using:</p>
  <pre><code>    context.eval(&quot;js&quot;, mappingTemplate);
  </code></pre>
  <p>Giving us two members that we can evaluate using:</p>
  <pre><code>    Value bindings = context.getBindings(&quot;js&quot;);
      final Value executionResult1 = bindings.getMember(&quot;hello&quot;)
                          .execute();
      final Value executionResult2 = bindings.getMember(&quot;helloAsync&quot;)
                          .execute();
  </code></pre>
  <p>As a result, the <code>executionResult2</code> would be a promise that can be completed within Java. My question is how I can reliably tell that <code>executionResult2</code> is in fact a promise, and not just a string like <code>executionResult1</code>. Currently, a naive and unreliable approach could be:</p>
  <pre><code>if (executionResult.toString().startsWith(&quot;Promise&quot;) &amp;&amp;
                      executionResult.hasMember(&quot;then&quot;) &amp;&amp; executionResult.hasMember(&quot;catch&quot;))
  </code></pre>
  <p>What are more reliable/elegant ways of recognizing a promise returned from JS?</p>