4 ms·
While not in the example that you replied to, it's assumed that you need the return value and want to do something with it. Think database query.
by xal 17y ago
While not in the example that you replied to, it's assumed that you need the return value and want to do something with it. Think database query.
- tolmasky 17y agoprecisely, ideally this should just work: var result = do_x() + do_y(); and could. Again, if I understand the documentation for node.js correctly, simply automatically appending a .wait() to every promise returned should in theory give you this behavior (and be as performance/non-blocking/etc) as the other method.
- swannodette 17y agovar resultp = add(do_x(), do_y(); do_z(resultp); do_foo(); You're code will block on add. This code only blocks on unrealized promises, that is do_foo gets to execute. This is _more_ concurrent.
- tolmasky 17y agoYou're no longer arguing your original point, or at least, you're no longer arguing against me. Your code and my code are now nearly identical, except for the fact that you use an add function and I use an add operator. In fact, if I just say "my add operator can manipulate promises" or whatever, then they become 100% the same. Since my original point was that I'd like to use a preprocessor to make asynchronous programming as easy to transition to as possible, this would be very easy to achieve (just replace exp1 + exp2 with add(exp1, exp2)). That's what I meant by "just work", not "almost work". The goal was to not have to use callbacks and nesting, a point that both our code snippets have reached, so I'm not sure exactly what we're arguing about.
- swannodette 17y agoHeh, we basically understand each other now, a couple more illustrative examples always helps point that out. And yes a preprocessor to convert operators to functions would be quite useful.