Hacker News new | comments | show | ask | jobs | submit login

You've got to ask, why is async programming used at all? The reason is twofold: first, the C10K problem, where too many threads kill performance, and second, sometimes you want to have multiple tasks run in parallel.

There are fairly simple syntactical solutions to both problems.

  result = doSomeAsyncTask()
  result.yield() // drops the thread, picks it up on response
  // do stuff with result here
This magic yield() doesn't exist (to my knowledge), but if it did, it would preserve linear code and also solve the C10K problem.

You could have similar code to solve the multiple task problem:

  result0 = doSomeAsyncTask0();
  result1 = doSomeAsyncTask1();

  while (result = getNextCompletedTask(result0, result1)) {
    // do something to result
  }

A Future in Java does something like this, but it doesn't drop threads.



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

Search: