xtd 1.0.0
Loading...
Searching...
No Matches
xtd::threading::tasks::task_factory Class Reference
Inheritance diagram for xtd::threading::tasks::task_factory:
xtd::object

Definition

Provides support for creating and scheduling Task objects.

Namespace
xtd::threading::tasks
Library
xtd.core
Examples
The following example uses the static xtd::threading::tasks::basic_task::factory property to make two calls to the xtd::threading::tasks::task_factory::start_new method. The first populates an array with the names of files in the user's MyDocuments directory, while the second populates an array with the names of subdirectories of the user's MyDocuments directory. It then calls the xtd::threading::tasks::task_factory::continue_when_all method, which displays information about the number of files and directories in the two arrays after the first two tasks have completed execution.
#include <xtd/xtd>
class example {
public:
static auto main() async_ {
auto tasks = array<task<>>(2);
auto files = array<string> {};
auto dirs = array<string> {};
tasks[0] = task<>::factory().start_new([&] {files = directory::get_files(docs_directory);});
tasks[1] = task<>::factory().start_new([&] {dirs = directory::get_directories(docs_directory);});
co_await task<>::factory().continue_when_all(tasks, [&] {
console::write_line("{} contains: ", docs_directory);
console::write_line(" {} subdirectories", dirs.length());
console::write_line(" {} files", files.length());
});
}
};
startup_(example::main);
// This code produces the following output :
//
// /Users/<username> contains:
// 63 subdirectories
// 24 files
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual auto length() const noexcept -> size_type
Gets a size that represents the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:122
@ my_documents
The My Documents folder. This member is equivalent to Personal.
Definition environment.hpp:153
static auto get_folder_path(environment::special_folder folder) -> xtd::string
Gets the path to the system special folder that is identified by the specified enumeration.
Definition environment.hpp:616
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:152
The xtd::threading::tasks namespace provides types that simplify the work of writing concurrent and a...
Definition itask.hpp:14

Public Methods

auto continue_when_all (xtd::iterable auto &&tasks, auto &&action) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
auto continue_when_all (xtd::iterable auto &&tasks, auto &&action, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
auto continue_when_all (xtd::iterable auto &&tasks, auto &&action, const xtd::any_object &state) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()(std::declval< const xtd::any_object & >()))> >
template<typename result_t>
auto continue_when_all (xtd::iterable auto &&tasks, auto &&action, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(action(std::declval< const xtd::any_object & >()))> >
auto continue_when_any (xtd::iterable auto &&tasks, auto &&action) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
auto continue_when_any (xtd::iterable auto &&tasks, auto &&action, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
auto continue_when_any (xtd::iterable auto &&tasks, auto &&action, const xtd::any_object &state) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()(std::declval< const xtd::any_object & >()))> >
template<typename result_t>
auto continue_when_any (xtd::iterable auto &&tasks, auto &&action, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(action(std::declval< const xtd::any_object & >()))> >
auto start_new (auto &&action) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
 Creates and starts a task.
auto start_new (auto &&action, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
 Creates and starts a task.
auto start_new (auto &&action, const xtd::any_object &state) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()(std::declval< const xtd::any_object & >()))> >
 Creates and starts a task.
template<typename result_t>
auto start_new (auto &&action, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(action(std::declval< const xtd::any_object & >()))> >
 Creates and starts a task.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto equals (const object &obj) const noexcept -> bool
 Determines whether the specified object is equal to the current object.
virtual auto get_hash_code () const noexcept -> xtd::usize
 Serves as a hash function for a particular type.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto to_string () const -> xtd::string
 Returns a xtd::string that represents the current object.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.

Member Function Documentation

◆ start_new() [1/4]

auto xtd::threading::tasks::task_factory::start_new ( auto && action) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
inlinenodiscard

Creates and starts a task.

Parameters
actionThe action delegate to execute asynchronously.
Returns
The started task.
Remarks
Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task.Start method to schedule the task for execution.

◆ start_new() [2/4]

auto xtd::threading::tasks::task_factory::start_new ( auto && action,
const xtd::threading::cancellation_token & cancellation_token ) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()())> >
inlinenodiscard

Creates and starts a task.

Parameters
actionThe action delegate to execute asynchronously.
Returns
The started task.
Remarks
Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task.Start method to schedule the task for execution.

◆ start_new() [3/4]

auto xtd::threading::tasks::task_factory::start_new ( auto && action,
const xtd::any_object & state ) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(std::declval< decltype(action)>()(std::declval< const xtd::any_object & >()))> >
inlinenodiscard

Creates and starts a task.

Parameters
actionThe action delegate to execute asynchronously.
Returns
The started task.
Remarks
Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task.Start method to schedule the task for execution.

◆ start_new() [4/4]

template<typename result_t>
auto xtd::threading::tasks::task_factory::start_new ( auto && action,
const xtd::any_object & state,
const xtd::threading::cancellation_token & cancellation_token ) const -> xtd::threading::tasks::task< xtd::raw_type< decltype(action(std::declval< const xtd::any_object & >()))> >
inlinenodiscard

Creates and starts a task.

Parameters
actionThe action delegate to execute asynchronously.
Returns
The started task.
Remarks
Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task.Start method to schedule the task for execution.

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