当向Executor(例如tf::Executor::run)提交任务流时,Executor返回一个tf::Future对象,该对象将保存执行结果。tf::Future是来自std::future的派生类。除了std::future的基本方法外,您还可以调用tf::Future::cancel来取消正在运行的任务流的执行。以下示例取消了任务流的提交,该任务流包含1000个任务,每个任务运行一秒钟。
#include <taskflow/taskflow.hpp>
int main() {
tf::Executor executor;
tf::Taskflow taskflow;
for(int i=0; i<1000; i++) {
taskflow.emplace([](){
std::this_thread::sleep_for(std::chrono::seconds(1