Awaiting thenables

Brian Terlson Brian.Terlson at microsoft.com
Fri Jun 26 21:16:49 UTC 2015


Yes, at least the current spec literally just calls Promise.resolve on any awaited value. See step 12: http://tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-start. So it’s identical semantics to `Promise.resolve(thenable)`.

From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Jordan Harband
Sent: Friday, June 26, 2015 2:07 PM
To: Mark S. Miller <erights at google.com>
Cc: Francisco Tolmasky <tolmasky at gmail.com>; es-discuss <es-discuss at mozilla.org>
Subject: Re: Awaiting thenables

so, in other words, `await thenable` would wrap the thenable in `Promise.resolve`, which would ensure it fires on the next tick?

On Fri, Jun 26, 2015 at 12:36 PM, Mark S. Miller <erights at google.com<mailto:erights at google.com>> wrote:

It would be postponed to a later job, i.e., turn of the event loop.

--
  Cheers,
  MarkM

On Jun 26, 2015 11:49 AM, "Francisco Tolmasky" <tolmasky at gmail.com<mailto:tolmasky at gmail.com>> wrote:
Apologies, I’m aware the last example didn’t make sense. What I meant was more along the lines of the following:

setImmediateOrOtherNextRunLoopMethod(function() { console.log(6) })
console.log(await { then: function(x) { x(5) } })

In other words, would the “then” fire on the same run loop (since it isnt a fancy Promise), or still have the underlying await engine (step function) make sure it takes place on the next iteration (and in this case thus possibly make it show up after the 6 instead of beefore).


On Fri, Jun 26, 2015 at 11:40 AM, Francisco Tolmasky <tolmasky at gmail.com<mailto:tolmasky at gmail.com>> wrote:
Out of curiosity, in ES7, would the following code:

console.log(await { then: function(x) { x(5) } })
console.log(6)

Print out 5 then 6, or still 6 then 5? In other words, is the asynchronousness gauranteed by the await, or by the underlying Promise implementation?


--
Francisco Tolmasky
www.tolmasky.com<http://www.tolmasky.com>
tolmasky at gmail.com<mailto:tolmasky at gmail.com>



--
Francisco Tolmasky
www.tolmasky.com<http://www.tolmasky.com>
tolmasky at gmail.com<mailto:tolmasky at gmail.com>

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>
https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150626/ada063d9/attachment-0001.html>


More information about the es-discuss mailing list