You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the mean-time someone migth use functions like below, to get the same behavior as async / await. Instead of await, use yield.
# generator-function to Promise to get async-await behaviour by using 'yield' for 'await'
def genToProm(generatorFunction, *args):
def promiseFunction(resolve, reject):
gen = generatorFunction(*args) # make generator from generator-function
def step(nextF):
next = None
try:
next = nextF()
except Exception as e: # finished with failure, reject the promise
reject(e)
return
if next.done: # finished with success, resolve the promise
resolve(next.value)
return
# not finished, chain off the yielded promise and `step` again
Promise.resolve(next.value).then(
lambda v: step(lambda: gen.js_next(v)),
lambda e: step(lambda: gen.throw(e)))
step(lambda: gen.js_next(None))
return __new__(Promise(promiseFunction))
# gives an promise with as result the parameter function result
# function will be started after at least *delay* milliseconds
def async(delay, func, *args):
def promiseFunction(resolve, reject):
def timeoutFunction():
try:
resolve(func(*args))
except Exception as e:
reject(e)
setTimeout(timeoutFunction, delay)
return __new__(Promise(promiseFunction))
Kind regards,
Pieter Jan
(if you don't like this message at this place, feel free to remove if possible. I'm just enthousiastic about Transcrypt and want to share my experiments)
Thanks!
Had just downloaded v54 for Linux, but now they already have a new version again.
I’ll install it and experiment with it.
Would be nice to have async / await.
I’ll first have to read a bit more about all the intricacies of coroutines, but as it sounds, it may be time to add them...
Jacques
Async functions are now supported in majority of browsers (AFAICT, 66%)
It should be very simple to implement, if Transcrypt sees a function is a asyncio.coroutine (or an async function), it just can put 'async ' before 'function blah(blah, blah, blah)', and emit await where an async function is 'await'-ing a value.
I've been stuck on this for a long time, been using Bluebird.coroutine for a while now, but I do hate using generators for a thing they weren't made for, I'd really appreciate the syntactic sugar for async def.
Activity
pjbonestroo commentedon Oct 29, 2016
In the mean-time someone migth use functions like below, to get the same behavior as async / await. Instead of await, use yield.
One can use these functions like below:
Kind regards,
Pieter Jan
(if you don't like this message at this place, feel free to remove if possible. I'm just enthousiastic about Transcrypt and want to share my experiments)
axgkl commentedon Oct 30, 2016
there is a go to javascript transpiler where we could learn from, they fully support goroutines, see here how they are doing it (high level) https://github.com/gopherjs/gopherjs#goroutines
JdeH commentedon Nov 4, 2016
Postponed until at least supported by Google Closure, and preferably also by a significant part of the newest browser versions.
pjbonestroo commentedon Dec 2, 2016
Chrome now supports the async and await JavaScript keywords.
See Software-update: Google Chrome 55.0.2883.75
https://tweakers.net/downloads/39301/google-chrome-550288375.html
https://developers.google.com/web/fundamentals/getting-started/primers/async-functions
JdeH commentedon Dec 3, 2016
JdeH commentedon Jun 16, 2017
Seems this should come to life again by now...
mmjee commentedon Jun 19, 2017
https://caniuse.com/#feat=async-functions
Async functions are now supported in majority of browsers (AFAICT, 66%)
It should be very simple to implement, if Transcrypt sees a function is a asyncio.coroutine (or an async function), it just can put 'async ' before 'function blah(blah, blah, blah)', and emit await where an async function is 'await'-ing a value.
^ Fairly equivalent
mmjee commentedon Jun 28, 2017
I've been stuck on this for a long time, been using Bluebird.coroutine for a while now, but I do hate using generators for a thing they weren't made for, I'd really appreciate the syntactic sugar for async def.
JdeH commentedon Jun 28, 2017
That certainly looks simple enough.
Will delve into this right now...
JdeH commentedon Jul 6, 2017
A first stab, global functions only.
This should now work.
Note that it requires the -e 6 switch.
Main gotcha was how to get Google Closure to accept ES8 code.
JdeH commentedon Jul 7, 2017
Following code from development/manual_tests/async_await now works correctly: