I'm trying to write an adapter to Flow Graph that imitates a pipeline-like synchronous function call. But I don't understand how to block and wait for the output for a specific token. Calling wait_for_all
on the graph doesn't help as I don't need to wait for all values. Can anybody suggest a solution?
template <typename TOutput, typename TInput>
class FlowPathAdapter {
public:
TOutput operator()(const TInput& val) {
m_input->try_put(val);
TOutput result;
// What should be done here to ensure that
// m_output returns the result corresponding to this specific token?
m_output->try_get(result);
return result;
}
private:
// input and output are connected in some graph constructed outside the adapter
std::shared_ptr<tbb::flow::receiver<TInput>> m_input;
std::shared_ptr<tbb::flow::sender<TOutput>> m_output;
};