Hacker News new | ask | show | jobs
by mcintyre1994 2975 days ago
Python doesn't really have the syntax for it, the promise library uses lambda which is pretty bulky: https://pypi.org/project/promise/

I wonder if you could do something nicer using the `with` syntax?

    with async_fn(with, params) as result:
        do_something(result)
    this_runs_sync()
    then_this_does()
It's still going to be annoying when they nest, maybe an async with which makes its whole content act like promises with `then` calls?

    async with fetch_thing() as result:
        json = async_jsonify(result)
        post_result = async_post(json)
        json_result = async_jsonify(post_result)
    then_sync_stuff()
Though you also want to be able to return promises, I suppose you could allow `return async with`, and you also need to be able to catch them. Not sure if this makes any sense to look further at, but I don't think we're getting arrow functions and the JS syntax without those is pretty clunky.