![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
FutureBoost , Chapter 1. Fiber , Futures
|
![]() | Note |
---|---|
Отложенное будущее не поддерживается. |
future<>
<future<>
>содержитобщее состояние, которое не разделяется ни с каким другим будущим.
#include <boost/fiber/future/future.hpp> namespace boost { namespace fibers { template< typename R > class future { public: future() noexcept; future( future const& other) = delete; future & operator=( future const& other) = delete; future( future && other) noexcept; future & operator=( future && other) noexcept; ~future(); bool valid() const noexcept; shared_future< R > share(); R get(); // member only of generic future template R & get(); // member only of future< R & > template specialization void get(); // member only of future< void > template specialization std::exception_ptr get_exception_ptr(); void wait() const; template< class Rep, class Period > future_status wait_for( std::chrono::duration< Rep, Period > const& timeout_duration) const; template< typename Clock, typename Duration > future_status wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time) const; }; }}
future() noexcept;
future( future && other) noexcept;
~future();
Уничтожает будущее, отказывается от собственности.
<~future()
>неблокирует вызывающее волокно.
Рассмотрим последовательность, такую как:
Окончательный звонок<set_value()
>удался, но значение тихо отбрасывается: из этого<promise<>
>не может быть получено никакого дополнительного<future<>
>.
operator=
()future & operator=( future && other) noexcept;
,из других<this
>. После этого<false==
other.valid()
>.
Ничего.
valid
()bool valid() const noexcept;
Возвращается<true
>, если будущее содержитобщее состояние.
Ничего.
share
()shared_future< R > share();
Переместите государство в<shared_future<>
>.
<shared_future<>
>, содержащееобщее состояние, ранее принадлежавшее<*this
>.
<future_error
>с ошибкой<future_errc::no_state
>.
get
()R get(); // member only of generic future template R & get(); // member only of future< R & > template specialization void get(); // member only of future< void > template specialization
<true==
valid()
>
<promise::set_value()
>или<promise::set_exception()
>называется. Если<promise::set_value()
>называется, то возвращает значение. Если<promise::set_exception()
>называется, то бросает указанное исключение.
<future_error
>с ошибкой<future_errc::no_state
>,<future_errc::broken_promise
>. Исключение составляет<promise::set_exception()
>.
get_exception_ptr
()std::exception_ptr get_exception_ptr();
<true==
valid()
>
<promise::set_value()
>или<promise::set_exception()
>. Если<set_value()
>называется, то возвращается построенный по умолчанию<std::exception_ptr
>. Если<set_exception()
>называется, то возвращается<std::exception_ptr
>.
<future_error
>с ошибкой<future_errc::no_state
>.
<get_exception_ptr()
>неделает<future
>недействительным. После звонка<get_exception_ptr()
>вы можете позвонить<future::get()
>.
wait
()void wait();
<future_error
>с ошибкой<future_errc::no_state
>.
wait_for
()template< class Rep, class Period > future_status wait_for( std::chrono::duration< Rep, Period > const& timeout_duration) const;
<promise::set_value()
>или<promise::set_exception()
>, или<timeout_duration
>уже прошло.
А<future_status
>возвращается с указанием причины возвращения.
<future_error
>с условием ошибки<future_errc::no_state
>или исключениями, связанными с тайм-аутом.
wait_until
()template< typename Clock, typename Duration > future_status wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time) const;
<promise::set_value()
>или<promise::set_exception()
>, или<timeout_time
>уже прошло.
А<future_status
>возвращается с указанием причины возвращения.
<future_error
>с условием ошибки<future_errc::no_state
>или исключениями, связанными с тайм-аутом.
shared_future<>
<shared_future<>
>содержитобщее состояние, которое может быть разделено с другими<shared_future<>
>экземплярами.
#include <boost/fiber/future/future.hpp> namespace boost { namespace fibers { template< typename R > class shared_future { public: shared_future() noexcept; ~shared_future(); shared_future( shared_future const& other); shared_future( future< R > && other) noexcept; shared_future( shared_future && other) noexcept; shared_future & operator=( shared_future && other) noexcept; shared_future & operator=( future< R > && other) noexcept; shared_future & operator=( shared_future const& other) noexcept; bool valid() const noexcept; R const& get(); // member only of generic shared_future template R & get(); // member only of shared_future< R & > template specialization void get(); // member only of shared_future< void > template specialization std::exception_ptr get_exception_ptr(); void wait() const; template< class Rep, class Period > future_status wait_for( std::chrono::duration< Rep, Period > const& timeout_duration) const; template< typename Clock, typename Duration > future_status wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time) const; }; }}
shared_future();
shared_future( future< R > && other) noexcept; shared_future( shared_future && other) noexcept;
Построение общего будущего собщим состояниемдругого. После строительства<false
==other.valid()
>.
Ничего.
shared_future( shared_future const& other) noexcept;
Построение общего будущего собщим состояниемдругого. После строительства<other.valid()
>остается без изменений.
Ничего.
~shared_future();
Уничтожает совместное будущее; право собственности прекращается, если оно не распространяется.
<~shared_future()
>неблокирует вызывающее волокно.
operator=
()shared_future & operator=( future< R > && other) noexcept; shared_future & operator=( shared_future && other) noexcept; shared_future & operator=( shared_future const& other) noexcept;
Перемещает или копируетобщее состояниедругого в<this
>. После назначения состояние<other.valid()
>зависит от того, какая перегрузка была вызвана: без изменений для перегрузки, принимающей<shared_future
const&
>, в противном случае<false
>.
Ничего.
valid
()bool valid() const noexcept;
Возвращается<true
>, если общее_будущее содержитобщее состояние.
Ничего.
get
()R const& get(); // member only of generic shared_future template R & get(); // member only of shared_future< R & > template specialization void get(); // member only of shared_future< void > template specialization
<true==
valid()
>
<promise::set_value()
>или<promise::set_exception()
>называется. Если<promise::set_value()
>называется, то возвращает значение. Если<promise::set_exception()
>называется, то бросает указанное исключение.
<future_error
>с ошибкой<future_errc::no_state
>,<future_errc::broken_promise
>. Исключение составляет<promise::set_exception()
>.
get_exception_ptr
()std::exception_ptr get_exception_ptr();
<true==
valid()
>
<promise::set_value()
>или<promise::set_exception()
>. Если<set_value()
>называется, то возвращается построенный по умолчанию<std::exception_ptr
>. Если<set_exception()
>называется, то возвращается<std::exception_ptr
>.
<future_error
>с ошибкой<future_errc::no_state
>.
<get_exception_ptr()
>делаетненедействительным<shared_future
>. После звонка<get_exception_ptr()
>вы можете позвонить<shared_future::get()
>.
wait
()void wait();
<future_error
>с ошибкой<future_errc::no_state
>.
wait_for
()template< class Rep, class Period > future_status wait_for( std::chrono::duration< Rep, Period > const& timeout_duration) const;
<promise::set_value()
>или<promise::set_exception()
>, или<timeout_duration
>уже прошло.
А<future_status
>возвращается с указанием причины возвращения.
<future_error
>с условием ошибки<future_errc::no_state
>или исключениями, связанными с тайм-аутом.
wait_until
()template< typename Clock, typename Duration > future_status wait_until( std::chrono::time_point< Clock, Duration > const& timeout_time) const;
<promise::set_value()
>или<promise::set_exception()
>, или<timeout_time
>уже прошло.
А<future_status
>возвращается с указанием причины возвращения.
<future_error
>с условием ошибки<future_errc::no_state
>или исключениями, связанными с тайм-аутом.
fibers::async()
#include <boost/fiber/future/async.hpp> namespace boost { namespace fibers { template< class Function, class ... Args > future< std::result_of_t< std::decay_t< Function >( std::decay_t< Args > ... ) > > async( Function && fn, Args && ... args); template< class Function, class ... Args > future< std::result_of_t< std::decay_t< Function >( std::decay_t< Args > ... ) > > async(launch
policy, Function && fn, Args && ... args); template< typenameStackAllocator
, class Function, class ... Args > future< std::result_of_t< std::decay_t< Function >( std::decay_t< Args > ... ) > > async(launch
policy,std::allocator_arg_t
,StackAllocator
salloc, Function && fn, Args && ... args); }}
<fn
>в<fiber
>и возвращает<future<>
>.
future< std::result_of_t< std::decay_t< Function >( std::decay_t< Args > ... ) > >
общее состояние, связанное с асинхронным выполнением<fn
>.
<fiber_error
>или<future_error
>при возникновении ошибки.
Перегрузки, принимающие<std::allocator_arg_t
>, используют пройденное<StackAllocator
>при строительстве запущенного<fiber
>. Перегрузки, принимающие<launch
>, используют пройденное<launch
>при строительстве запущенного<fiber
>. По умолчанию<launch
><post
>, как для<fiber
>конструктора.
![]() | Note |
---|---|
Отложенное будущее не поддерживается. |
Статья Future раздела Chapter 1. Fiber Futures может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.
реклама |