Taskflow  3.2.0-Master-Branch
Loading...
Searching...
No Matches
tf::Future< T > Class Template Reference

class to access the result of an execution More...

#include <taskflow.hpp>

Inheritance diagram for tf::Future< T >:
Collaboration diagram for tf::Future< T >:

Public Member Functions

 Future ()=default
 default constructor
 
 Future (const Future &)=delete
 disabled copy constructor
 
 Future (Future &&)=default
 default move constructor
 
Futureoperator= (const Future &)=delete
 disabled copy assignment
 
Futureoperator= (Future &&)=default
 default move assignment
 
bool cancel ()
 cancels the execution of the running taskflow associated with this future object
 

Friends

class Executor
 
class Subflow
 

Detailed Description

template<typename T>
class tf::Future< T >

class to access the result of an execution

tf::Future is a derived class from std::future that will eventually hold the execution result of a submitted taskflow (tf::Executor::run) or an asynchronous task (tf::Executor::async, tf::Executor::silent_async). In addition to the base methods inherited from std::future, you can call tf::Future::cancel to cancel the execution of the running taskflow associated with this future object. The following example cancels a submission of a taskflow that contains 1000 tasks each running one second.

tf::Executor executor;
tf::Taskflow taskflow;
for(int i=0; i<1000; i++) {
taskflow.emplace([](){
});
}
// submit the taskflow
tf::Future fu = executor.run(taskflow);
// request to cancel the submitted execution above
fu.cancel();
// wait until the cancellation finishes
fu.get();
class to create an executor for running a taskflow graph
Definition executor.hpp:50
tf::Future< void > run(Taskflow &taskflow)
runs a taskflow once
Definition executor.hpp:1573
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:742
class to access the result of an execution
Definition core/taskflow.hpp:571
bool cancel()
cancels the execution of the running taskflow associated with this future object
Definition core/taskflow.hpp:642
class to create a taskflow object
Definition core/taskflow.hpp:73
T sleep_for(T... args)

Member Function Documentation

◆ cancel()

template<typename T >
bool tf::Future< T >::cancel ( )

cancels the execution of the running taskflow associated with this future object

Returns
true if the execution can be cancelled or false if the execution has already completed

When you request a cancellation, the executor will stop scheduling any tasks onwards. Tasks that are already running will continue to finish (non-preemptive). You can call tf::Future::wait to wait for the cancellation to complete.


The documentation for this class was generated from the following file: