xtd 1.0.0
Loading...
Searching...
No Matches
xtd::threading::tasks::basic_task< result_t > Class Template Reference
Inheritance diagram for xtd::threading::tasks::basic_task< result_t >:
xtd::threading::tasks::task_object xtd::threading::tasks::itask xtd::iasync_result xtd::object xtd::interface xtd::interface xtd::threading::tasks::task< void > xtd::threading::tasks::task< void > xtd::threading::tasks::wtask< result_t > xtd::threading::tasks::wtask< result_t >

Definition

template<typename result_t = void>
class xtd::threading::tasks::basic_task< result_t >

Represents a base class for asynchronous operation.

template<typename result_t = void>
Represents the status of an asynchronous operation.
Definition iasync_result.hpp:25
basic_task(const xtd::func< result_t > &func)
Initializes a new xtd::threading::tasks::basic_task <result_t> with the specified function.
Definition basic_task.hpp:75
Represents an interface for an asynchronous operation.
Definition itask.hpp:19
Represents an asynchronous operation object.
Definition task_object.hpp:28
Header
#include <xtd/threading/tasks/task_object>
Namespace
xtd::threading
Library
xtd.core
Remarks
This is tha base class for xtd::threading::tasks::task <> and xtd::threading::tasks::task <result_t>.

Public Fields

static constexpr xtd::usize wait_timeout
 Indicates that a xtd::threading::wait_handle::wait_any operation timed out before any of the wait handles were signaled. This field is constant.

Public Constructors

 basic_task (const xtd::func< result_t > &funcfunc)
 Initializes a new xtd::threading::tasks::basic_task <result_t> with the specified function.
 basic_task (const xtd::func< result_t > &funcfunc, const xtd::threading::cancellation_token &cancellation_token)
 basic_task (const xtd::func< result_t, const xtd::any_object & > &funcfunc, const xtd::any_object &state)
 basic_task (const xtd::func< result_t > &funcfunc, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token)

Public Properties

auto async_state () const noexcept -> xtd::any_object override
 Gets a user-defined object that qualifies or contains information about an asynchronous operation.
auto creation_options () const noexcept -> xtd::threading::tasks::task_creation_options
auto exception () const noexcept -> xtd::ref< xtd::exception >
auto id () const noexcept -> xtd::usize override
 Gets an ID for this xtd::threading::tasks::task instance.
auto is_canceled () const noexcept -> bool
auto is_completed () const noexcept -> bool override
 Gets a value that indicates whether the asynchronous operation has completed.
auto is_faulted () const noexcept -> bool
auto status () const noexcept -> xtd::threading::tasks::task_status

Public Methods

auto continue_with (xtd::action<> continuation) -> void
auto rethrow_exception () -> void
auto run_synchronously () -> void
auto start () -> void override
 Starts the xtd::threading::tasks::task, scheduling it for execution to the current xtd::threading::tasks::task_scheduler.
auto wait () -> void override
 Waits for the xtd::threading::tasks::task to complete execution.
auto wait (xtd::int32 milliseconds_timeout) -> bool override
 Waits for the xtd::threading::tasks::task to complete execution with specified milliseconds timout.
auto wait (xtd::int32 milliseconds_timeout, xtd::threading::cancellation_token &cancellation_token) -> bool override
 Waits for the xtd::threading::tasks::task to complete execution with specified milliseconds timout and cancellation token.
auto wait (const xtd::time_span &timeout) -> bool override
 Waits for the xtd::threading::tasks::task to complete execution with specified timout.
auto wait (const xtd::time_span &timeout, xtd::threading::cancellation_token &cancellation_token) -> bool override
 Waits for the xtd::threading::tasks::task to complete execution with specified timout and cancellation token.

Public Static Properties

static auto completed_task () -> task< result_t >
static auto current_id () noexcept -> xtd::usize
static auto factory () noexcept -> const xtd::threading::tasks::task_factory &

Public Static Methods

static auto from_cancelation (const xtd::threading::cancellation_token &cancellation_token) -> task< result_t >
template<typename from_exception_t>
static auto from_exception (from_exception_t exception) -> task< result_t >
static auto delay (const xtd::time_span &delay) -> task<>
static auto delay (const xtd::time_span &delay, const xtd::threading::cancellation_token &cancellation_token) -> task<>
static auto delay (xtd::int32 milliseconds_delay) -> task<>
static auto delay (xtd::int32 milliseconds_delay, const xtd::threading::cancellation_token &cancellation_token) -> task<>
static auto run (const xtd::func< result_t > &funcfunc) -> task< result_t >
static auto run (const xtd::func< result_t > &funcfunc, const xtd::threading::cancellation_token &cancellation_token) -> task< result_t >
static auto run (const xtd::func< result_t, const xtd::any_object & > &funcfunc, const xtd::any_object &state) -> task< result_t >
static auto run (const xtd::func< result_t, const xtd::any_object & > &funcfunc, const xtd::any_object &state, const xtd::threading::cancellation_token &cancellation_token) -> task< result_t >
template<typename collection_t>
static auto wait_all (const collection_t &tasks) -> bool
template<typename collection_t>
static auto wait_all (const collection_t &tasks, xtd::int32 milliseconds_timeout) -> bool
template<typename collection_t>
static auto wait_all (const collection_t &tasks, const xtd::time_span &timeout) -> bool
template<typename collection_t>
static xtd::usize wait_any (const collection_t &tasks)
template<typename collection_t>
static xtd::usize wait_any (const collection_t &tasks, int32 milliseconds_timeout)
template<typename collection_t>
static xtd::usize wait_any (const collection_t &tasks, const time_span &timeout)
template<typename ... items_t>
static auto when_all (items_t &&... items) -> task<>
template<typename ... items_t>
static auto when_any (items_t &&... items) -> task< xtd::usize >

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.

Constructor & Destructor Documentation

◆ basic_task()

template<typename result_t = void>
xtd::threading::tasks::basic_task< result_t >::basic_task ( const xtd::func< result_t > & func)
inline

Initializes a new xtd::threading::tasks::basic_task <result_t> with the specified function.

Parameters
funcThe delegate that represents the code to execute in the task. When the function has completed, the task's xtd::threading::tasks::basic_task::result property will be set to return the result value of the function.

Member Function Documentation

◆ async_state()

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::async_state ( ) const -> xtd::any_object
inlinenodiscardoverridevirtualnoexcept

Gets a user-defined object that qualifies or contains information about an asynchronous operation.

Returns
A user-defined object that qualifies or contains information about an asynchronous operation.
Remarks
This property returns the object that is the last parameter of the method that initiates an asynchronous operation.
Notes to Implementers
Implement this property to allow the caller of an asynchronous operation to obtain an application-defined object specified at the start of the operation.
Notes to Callers
This object can be used to pass state information for the asynchronous operation to an AsyncCallback that you provide.

Implements xtd::iasync_result.

◆ id()

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::id ( ) const -> xtd::usize
inlinenodiscardoverridevirtualnoexcept

Gets an ID for this xtd::threading::tasks::task instance.

Returns
The identifier that is assigned by the system to this xtd::threading::tasks::task instance.
Remarks
Task IDs are assigned on-demand and do not necessarily represent the order in which task instances are created. Note that although collisions are very rare, task identifiers are not guaranteed to be unique.
To get the task ID of the currently executing task from within code that task is executing, use the xtd::threading::tasks::task::current_id property.

Implements xtd::threading::tasks::itask.

◆ is_completed()

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::is_completed ( ) const -> bool
inlinenodiscardoverridevirtualnoexcept

Gets a value that indicates whether the asynchronous operation has completed.

Returns
true if the operation is complete; otherwise, false.
Remarks
When this property is true, you can assume it is safe to discard any resources you allocate for use by the asynchronous operation.
Notes to Implementers
Implementers will typically return the value of a private field or internal test as the value of this property.
Notes to Callers
Clients that poll for operation status (as opposed to waiting on a synchronization object) use this property to determine the status of the operation.

Implements xtd::iasync_result.

◆ start()

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::start ( ) -> void
inlineoverridevirtual

Starts the xtd::threading::tasks::task, scheduling it for execution to the current xtd::threading::tasks::task_scheduler.

Implements xtd::threading::tasks::itask.

◆ wait() [1/5]

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::wait ( ) -> void
inlineoverridevirtual

Waits for the xtd::threading::tasks::task to complete execution.

Implements xtd::threading::tasks::itask.

◆ wait() [2/5]

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::wait ( xtd::int32 milliseconds_timeout) -> bool
inlineoverridevirtual

Waits for the xtd::threading::tasks::task to complete execution with specified milliseconds timout.

Parameters
milliseconds_timeoutThe number of milliseconds to wait, or xtd::threading::timeout::infinite (-1) to wait indefinitely.
Returns
true if the xtd::threading::tasks::task completed execution within the allotted time; otherwise, false.

Implements xtd::threading::tasks::itask.

◆ wait() [3/5]

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::wait ( xtd::int32 milliseconds_timeout,
xtd::threading::cancellation_token & cancellation_token ) -> bool
inlineoverridevirtual

Waits for the xtd::threading::tasks::task to complete execution with specified milliseconds timout and cancellation token.

Parameters
milliseconds_timeoutThe number of milliseconds to wait, or xtd::threading::timeout::infinite (-1) to wait indefinitely.
Returns
true if the xtd::threading::tasks::task completed execution within the allotted time; otherwise, false.

Implements xtd::threading::tasks::itask.

◆ wait() [4/5]

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::wait ( const xtd::time_span & timeout) -> bool
inlineoverridevirtual

Waits for the xtd::threading::tasks::task to complete execution with specified timout.

Parameters
timeoutA xtd::time_span that represents the number of milliseconds to wait, or a xtd::threading::timeout::infinite_time_span that represents -1 milliseconds to wait indefinitely.
Returns
true if the xtd::threading::tasks::task completed execution within the allotted time; otherwise, false.

Implements xtd::threading::tasks::itask.

◆ wait() [5/5]

template<typename result_t = void>
auto xtd::threading::tasks::basic_task< result_t >::wait ( const xtd::time_span & timeout,
xtd::threading::cancellation_token & cancellation_token ) -> bool
inlineoverridevirtual

Waits for the xtd::threading::tasks::task to complete execution with specified timout and cancellation token.

Parameters
timeoutA xtd::time_span that represents the number of milliseconds to wait, or a xtd::threading::timeout::infinite_time_span that represents -1 milliseconds to wait indefinitely.
Returns
true if the xtd::threading::tasks::task completed execution within the allotted time; otherwise, false.

Implements xtd::threading::tasks::itask.

Member Data Documentation

◆ wait_timeout

template<typename result_t = void>
xtd::usize xtd::threading::tasks::basic_task< result_t >::wait_timeout
staticconstexpr

Indicates that a xtd::threading::wait_handle::wait_any operation timed out before any of the wait handles were signaled. This field is constant.

Remarks
This field is one of the possible return values of xtd::threading::wait_handle::wait_any.

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