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

I like the pattern in the example a lot. We recently started doing something just like this in a Rails app at work that has to make quite a few API calls per request. In the right circumstances it makes a big difference in response time. Our approach was basically just this: https://gist.github.com/kevinmcconnell/8365521

I could definitely see how using a language that makes these sorts of operations simpler could lead to finding more cases where it's worth it.



> a language that makes these sorts of operations simpler

That's essentially what async/await is doing in C# (and hopefully eventually in C++).

For example the code in the original post could be in C# as:

    var facebookTestUser1 = CreateFacebookTestUser();
    var facebookTestUser2 = CreateFacebookTestUser();
    MakeFriends(facebookTestUser1, facebookTestUser2);
And asynchronously:

    var facebookTestUser1 = CreateFacebookTestUser();
    var facebookTestUser2 = CreateFacebookTestUser();
    MakeFriends(await facebookTestUser1, await facebookTestUser2);
Of course, the code inside CreateFacebookTestUser is going to have to change ;)


I don't think of Java of as a language that makes concurrent operations like this simple, but I do think there are libraries that make it easier. Hystrix's async command comes to mind: https://github.com/Netflix/Hystrix/wiki/How-To-Use#wiki-Asyn...

I expect most widely languages allow for libraries to make this easier, if it isn't integral to the language.




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

Search: