Reflection to know if executed within a generator/async ?

Andrea Giammarchi andrea.giammarchi at
Thu Dec 3 12:15:49 UTC 2015

Hi there,
  just writing down some thoughts about being able to understand if a
method/function has been  executed within a generator/async and is being

Rationale: API that would like to behave synchronously in some case,
returning Promises in other cases.


function fileGetContent(fileName) {
  // random example
  if (held) {
    return fetch(fileName).then((r)=>r.text());
  } else {
    var xhr = new XMLHttpRequest;'GET', fileName, false);
    return xhr.responseText;

Above example will virtually return always the same type and it could work
inside a generator or an  async function as long as it's being held.

Does any of this make sense? Is it worth exploring this pattern?

Thanks for any sort of thought.

Best  Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list