←back to thread

289 points kristoff_it | 2 comments | | HN request time: 0s | source
Show context
raluk ◴[] No.44609651[source]
One thing that most languages are lacking is expressing lazy return values. -> await f1() + await f2() and to express this concurently requres manually handing of futures.
replies(3): >>44609880 #>>44610056 #>>44610348 #
jayd16 ◴[] No.44610348[source]
you mean like?

   await Join(f1(), f2())
Although more realistically

   Promise1 = f1(); Promise2 = f2();
   await Join(Promise1, Promise2);
But also, futures are the expression of lazy values so I'm not sure what else you'd be asking for.
replies(1): >>44612839 #
1. raluk ◴[] No.44612839[source]
This is what i hand in mind whit "manually handing of futures". In this case you have to write

   Promise1 = f1(); Promise2 = f2();
   v1,v2 = await Join(Promise1, Promise2);
   return v1 + v2
I think this is just too much of synthactic noise.

On the other hand, it is necessary becase some of underlying async calls can be order dependend.

for example

    await sock.rec(1) == 'A' && await sock.rec(1) == 'B'
checks that first received socket byte is A and second is B. This is clearly order dependant that can't be executed concurrently out of order.
replies(1): >>44617730 #
2. jayd16 ◴[] No.44617730[source]
I suppose you'd have to make

    SumAsync(F1(),f2());
Buy it's kind of intractable, isn't it? Your language has to assume order dependency or independency and specify the other. Most seem to stick with lexical ordering implies execution order.

I think some use curly brace scoping to break up dependency. I want to say kotlin does something like this.

This is why they say async is a viral pattern but IMO that's because you're adding specificity and function coloring is necessary and good.