mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-19 02:12:24 +00:00
168 lines
4.2 KiB
Plaintext
168 lines
4.2 KiB
Plaintext
[/
|
|
Copyright Oliver Kowalke 2013.
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
(See accompanying file LICENSE_1_0.txt or copy at
|
|
http://www.boost.org/LICENSE_1_0.txt
|
|
]
|
|
|
|
[section:packaged_task Template `packaged_task<>`]
|
|
|
|
A __packaged_task__ wraps a callable target so that it can be called asynchronously.
|
|
|
|
template< typename R >
|
|
class packaged_task
|
|
{
|
|
public:
|
|
packaged_task() noexcept;
|
|
|
|
template< typename Fn >
|
|
explicit packaged_task( Fn && fn);
|
|
|
|
template< typename Fn, typename Allocator >
|
|
explicit packaged_task( boost::allocator_arg_t, Allocator const& alloc, Fn && fn);
|
|
|
|
packaged_task( packaged_task && other) noexcept;
|
|
|
|
packaged_task( packaged_task const& other) = delete;
|
|
|
|
~packaged_task();
|
|
|
|
packaged_task & operator=( packaged_task && other) noexcept;
|
|
|
|
packaged_task & operator=( packaged_task const& other) = delete;
|
|
|
|
void swap( packaged_task & other) noexcept;
|
|
|
|
operator safe_bool() const noexcept;
|
|
|
|
bool operator!() const noexcept;
|
|
|
|
bool valid() const noexcept;
|
|
|
|
future< R > get_future();
|
|
|
|
void operator()();
|
|
|
|
void reset();
|
|
};
|
|
|
|
[heading Default constructor `packaged_task()`]
|
|
|
|
packaged_task();
|
|
|
|
[variablelist
|
|
[[Effects:] [Constructs an object of class `packaged_task` with no shared state.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Templated constructor `template<> packaged_task()`]
|
|
|
|
template< typename Fn >
|
|
explicit packaged_task( Fn && fn);
|
|
|
|
template< typename Fn, typename Allocator >
|
|
explicit packaged_task( boost::allocator_arg_t, Allocator const& alloc, Fn && fn);
|
|
|
|
[variablelist
|
|
[[Effects:] [Constructs an object of class `packaged_task` with a shared state
|
|
and stores the callable target `fn` internally.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Move constructor]
|
|
|
|
packaged_task( packaged_task && other) noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Creates a packaged_task by moving the shared state from `other`.]]
|
|
[[Postcondition:] [`other` contains no valid shared state.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Destructor]
|
|
|
|
~packaged_task();
|
|
|
|
[variablelist
|
|
[[Effects:] [Destroyes `this` and abandons the shared state if shared state is
|
|
ready; store an ___future_error__ with error condition __broken_promise__
|
|
otherwise.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `operator=()`]
|
|
|
|
packaged_task & operator=( packaged_task && other) noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Transfers the ownership of shared state to `this`.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `swap()`]
|
|
|
|
void swap( packaged_task & other) noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Swaps the shared state between other and `this`.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `operator safe_bool()`]
|
|
|
|
operator safe_bool() const noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Returns `true` if packaged_task an non-empty shared state.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `operator!()`]
|
|
|
|
bool operator!() const noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Returns `true` if packaged_task an empty shared state.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `valid()`]
|
|
|
|
bool valid() const noexcept;
|
|
|
|
[variablelist
|
|
[[Effects:] [Returns `true` if packaged_task contains a shared state.]]
|
|
[[Throws:] [Nothing.]]
|
|
]
|
|
|
|
[heading Member function `get_future()`]
|
|
|
|
future< R > get_future();
|
|
|
|
[variablelist
|
|
[[Effects:] [Returns a __future__ with the same shared state.]]
|
|
[[Throws:] [__future_error__ with __already_retrieved__ or __no_state__.]]
|
|
]
|
|
|
|
[heading Member function `operator()()`]
|
|
|
|
void operator()();
|
|
|
|
[variablelist
|
|
[[Effects:] [Invokes the stored callable target.i Exceptions thrown by the
|
|
callable target are stored in the shared state.]]
|
|
[[Throws:] [__future_error__ with __no_state__.]]
|
|
]
|
|
|
|
[heading Member function `reset()`]
|
|
|
|
void reset();
|
|
|
|
[variablelist
|
|
[[Effects:] [Resets the shared state and abondons the result of previous
|
|
executions. A new shared state is constructed.]]
|
|
[[Throws:] [__future_error__ with __no_state__.]]
|
|
]
|
|
|
|
[endsect]
|