Reflection to know if executed within a generator/async ?

Bradley Meck bradley.meck at
Thu Dec 3 16:57:02 UTC 2015

I am against any semantics that expose how a function is used. I struggle
and many others do when this occurs in CSS (display varies depending on
container). I would also be hesitant to encourage things acting both
synchronously and asynchronously depending on how they are used. Changing
temporal behavior depending on usage is asking for race conditions.

On Thu, Dec 3, 2015 at 10:37 AM, Andrea Giammarchi <
andrea.giammarchi at> wrote:

> Uhm... you never closed that "will this value be .... thing and I'm
> expecting a "dary" answer like in few emails but my whole point is
> consuming  an API in different scenarios: held or synchronous.
> You can always create an API that always returns a Promise, that's nothing
> new for the language, but can you decide if it's he case to absolutely
> return a promise 'cause any other value would cause trouble within that
> generator or async function?
> On Thu, Dec 3, 2015 at 4:15 PM, John Lenz <concavelenz at> wrote:
>> I don't think being executed in a generator or async function is a good
>> signal that a promise should be returned (something needs to "await" the
>> promise).   The async function is really a chain of synchronous code split
>> at various points, during the synchronous parts the code would still need
>> to be synchronous and returning a promise would be wrong.   The real data
>> you need is "will this value be consumed by an 'await' expression or be
>> used to resolve a Promise and, in the general case,  that is not something
>> that can't be answered at the time your example function is executing.
>> On Thu, Dec 3, 2015 at 4:15 AM, Andrea Giammarchi <
>> andrea.giammarchi at> wrote:
>>> 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
>>> yielded/awaited.
>>> Rationale: API that would like to behave synchronously in some case,
>>> returning Promises in other cases.
>>> Example:
>>> ```js
>>> function fileGetContent(fileName) {
>>>   // random example
>>>   if (held) {
>>>     return fetch(fileName).then((r)=>r.text());
>>>   } else {
>>>     var xhr = new XMLHttpRequest;
>>>'GET', fileName, false);
>>>     xhr.send(null);
>>>     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
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list