I'm coding in c++, and I'm trying to load an image file asynchronously. After some research, I found some mentions about using boost::asio and boost::iostreams to do it. However, the documentation and example for boost::asio is mostly socket related, so it doesn't help me much.
Here is what I need:
- Load a file asynchronously and upon load completion, executes a callback function.(In my case, the callback function executes a javascript function object using v8 javascript engine)
- The callback function must be executed within the same thread as the main function. ( Because v8 is not thread safe.)
- Need to work on linux and windows. (separate implementations are ok)
So, something like this would be really nice:
async_read("test.jpg", &the_callback_function);
The function should not block, and upon file load completion, it should run 'the_callback_function'.
Edit: as joshperry pointed out, boost::asio might not be able to dispatch back to the main thread. So, I guess I don't have to limit to only boost::asio and boost:iostreams. Any c/c++ library that can help with this requirement should be fine. Thanks!