await on synchronous functions

Mark S. Miller erights at google.com
Fri Jul 17 22:14:46 UTC 2015


On Fri, Jul 17, 2015 at 3:06 PM, Alexander Jones <alex at weej.com> wrote:

> Changing a function from returning a Promise<T> to returning a T is just
> the same as changing it to return any other type.
>

This sounds like the old monad vs promise debate. EcmaScript promises have
already decided against the monad camp. Whether that decision is right or
wrong, it is behind us. Promises are not parametrically polymorphic over
all T. In particular when T is Promise<U>,
Promise<T> === Promise<Promise<U>> === Promise<U>.



> Your type annotations and refactoring tools should assist you in changing
> call-sites.
>
> -1 for awaiting non-Promises, from me.
>
> On 17 July 2015 at 19:27, Tom Van Cutsem <tomvc.be at gmail.com> wrote:
>
>> 2015-07-17 19:41 GMT+02:00 Andrea Giammarchi <andrea.giammarchi at gmail.com
>> >:
>>
>>> If I might, if there's one thing that has never particularly shone in
>>> JS, that is consistency.
>>>
>>> I see only two possibilities here: 1) it throws with non Promises 2) it
>>> "Promisify" anything that's not a Promise as if it was a
>>> `Promise.resolve(1)` ... but since there's too much magic in the second
>>> point, I'd rather stick with the first one.
>>>
>>
>> I would be highly in favor of (2). Think about a large program where you
>> refactor a single async function to no longer be async. Then I see no
>> reason why I should be forced to refactor all of its callers to remove the
>> await keyword. Going from sync to async requires refactoring because you're
>> introducing new potential interleaving hazards, but any code that is
>> already prepared to work with async functions (or promises in general)
>> should work equally fine on immediately resolved promises.
>>
>> regards,
>> Tom
>>
>>
>>
>>>
>>> Just my quick thoughts
>>>
>>> Best Regards
>>>
>>> On Fri, Jul 17, 2015 at 6:33 PM, Kevin Smith <zenparsing at gmail.com>
>>> wrote:
>>>
>>>> I know the spec for this isn't finalized, but what is the current
>>>>> direction for the behaviour when await is used on a function that is not
>>>>> marked async and doesn't return a Promise? Should it run immediately or
>>>>> wait for the next turn of the event loop?
>>>>>
>>>>
>>>> More generally, the question is: what should await do for non-promises?
>>>>
>>>>     await 1;
>>>>
>>>> Should it force a job to be queued?
>>>>
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150717/31749aaf/attachment.html>


More information about the es-discuss mailing list