Hacker News new | ask | show | jobs
by KingOfCoders 2229 days ago
Still we need a language where every function call is async and the runtime decides what to inline.
1 comments

Looking at my async code, I just don't see how that would make things more clear instead of less clear.

For example, something as simple as:

    const result1 = promise() // start this promise first but don't await it yet.
    // ...
    const results = await Promise.map([promise(), promise(), result1])
It's more that you don't need to add 'async' to each function, because every function is async. And working with promises automatically maps over them. Then if you want to 'unbox' the Promise you'd have a keyword, like await.

So instead of a.map(v => f(v)) ... or Promise.map(a, f) ... or a.map(f) ... it's just f(a).

If you then want the value, in the end, if at all (e.g. the web framework understands Promise and you return a Promise in your controller and not a value, you don't need await at all).

You'd need some syntax for Promise.all(...) though to "join" concurrent executions again.

The language should probably have some syntax for multiple writers, e.g. and atomic compareAndSet.

   shared v = { .... }
   v.change(v, f) 
where f has no side effects and can be executed again. With IO (DB) one would need support for idempotency ala Stripe.

But your functions would not have colors.