I have a WinJS app that uses WinRT component written in C++/CX. Component spawns a background thread that encapsulates work with a huge legacy thread-unsafe C++ library, which requires all calls to be made from the same thread.
I need to implement a producer/consumer pattern, where the background thread in the component is a producer, and UI thread in JavaScript app is a consumer.
The call part is easy, as JavaScript can call component methods (in UI thread), and C++ code will post a job into a queue for background thread.
The question is the callback: I need to post the data calculated by the C++ background thread into UI thread. I certainly can return an IAsyncOperation back to JavaScript, but I don't want UI thread to be blocked while this operation is waiting for an event from a background thread.
What are my options?