我正在尝试为 Flow Graph 编写一个适配器,该适配器模仿类似管道的同步函数调用。但我不明白如何阻止并等待特定令牌的输出。调用wait_for_all
图表并没有帮助,因为我不需要等待所有值。有人可以提出解决方案吗?
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;
};