Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The sample looks like any other closure-based framework, to me. Compare to C#, for instance, I can just do this:

  try { 
    var a = await Function1Async()
    var b = await Function2Async(a);
    try {
      var c = nonAsync(a,b);
      await AnotherThingAsync(c);
    } catch { ... }
  } catch { 
    ...
  }
  finally {
    ...
  } 
This generates the callback mess (every await is an async call), figures out the right parts of the exception/finally handlers to run, etc. etc. I don't see how this can be remotely approached if the only syntax you have is lambdas. You need some sort of rewriting system, either by a special keyword (C#), or monad-like thing (F# workflows) or something.


Not at all. Here is the equivalent pseudo code:

Function1Async() .flatMap(a -> a, Function2Async(a)) .map( (a, b) -> nonAsync(a, b)) .flatMap(c -> AnotherThingAsync(c)) .error(e -> catch) .complete( finally );

The real code would be a little more complicated but not much.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: