Finally I realized the importance of blogging. (Yeah... I m a tubelight, but Hey .. tubelight is brighter than a bulb). So how come such a late realization ? After such a long time , I encountered my old friend C++, yeah and was a very nasty encounter.
Well if you have read dilbert comic strips, you would definitely realized by now, that if you dont work on a particular programming language for more than 6 months, then you are as amateur as a school grad. Actually school grads will perform better. Anyways, the problem I came across was I needed to refactor, rather fix some part of the program which was initially written in a very sequential manner and needed to be scaled. After much hype of nodejs and similar frameworks on Async programming, I thought why not try Boost ASIO. Mind you this is not for the feint heart.
So here is what I do. Here is an excellent ppt . It relatively easier if you have prior background on Async programming. Time to test some sample programs in it.
Well if you have read dilbert comic strips, you would definitely realized by now, that if you dont work on a particular programming language for more than 6 months, then you are as amateur as a school grad. Actually school grads will perform better. Anyways, the problem I came across was I needed to refactor, rather fix some part of the program which was initially written in a very sequential manner and needed to be scaled. After much hype of nodejs and similar frameworks on Async programming, I thought why not try Boost ASIO. Mind you this is not for the feint heart.
So here is what I do. Here is an excellent ppt . It relatively easier if you have prior background on Async programming. Time to test some sample programs in it.
It compiles and executes. You will see that statement after 5 seconds. So, whats the BIG DEAL ?By calling the method async_wait() and passing the name of the handler()function as the single argument, you have actually initiated a asynchronous operation. As of now, the name of the function is passed on async_wait and function call is not yet made. As soon as the time goes off(5 seconds in this case), the function is then executed.
The run() in io_service ensures the main program doest terminate, thus giving back control to OS. Also, you can create mutiple handlers for the same io_service or can mutiplex it ( more on that later..)
The run() in io_service ensures the main program doest terminate, thus giving back control to OS. Also, you can create mutiple handlers for the same io_service or can mutiplex it ( more on that later..)