promise 클래스

비동기 공급자를 설명합니다.

구문

template <class Ty>
class promise;

멤버

공용 생성자

속성 설명
약속 promise 개체를 생성합니다.

공용 메서드

이름 설명
get_future 이 promise와 연관된 future를 반환합니다.
set_exception 예외를 나타내기 위해 이 promise의 결과를 원자 단위로 설정합니다.
set_exception_at_thread_exit 예외를 나타내기 위해 이 promise의 결과를 원자 단위로 설정하고 현재 스레드에 있는 모든 스레드 지역 개체가 제거된 후에만 통지를 전달합니다.
set_value 이 promise의 결과를 원자 단위로 설정하여 값을 나타냅니다.
set_value_at_thread_exit 값을 나타내기 위해 이 promise의 결과를 원자 단위로 설정하고 현재 스레드에 있는 모든 스레드 지역 개체가 제거된 후에만 통지를 전달합니다.
swap 이 promise의 연결된 비동기 상태를 지정한 개체의 연결된 비동기 상태와 교환합니다.

Public 연산자

속성 설명
promise::operator= 이 promise 개체의 공유 상태에 대한 할당입니다.

상속 계층 구조

약속

요구 사항

헤더:<future>

네임스페이스: std

promise::get_future

이 promise와 동일한 연결된 비동기 상태가 있는 future 개체를 반환합니다.

future<Ty> get_future();

설명

promise 개체가 비어 있는 경우 이 메서드는 error_codeno_statefuture_error를 throw합니다.

이 메서드가 연결된 비동기 상태가 동일한 promise 개체를 위해 호출된 경우 future_errorerror_codefuture_already_retrieved를 thorw합니다.

promise::operator=

지정된 promise 개체에서 연결된 비동기 상태를 전송합니다.

promise& operator=(promise&& Other) noexcept;

매개 변수

기타
promise 개체입니다.

Return Value

*this

설명

이 연산자는 연결된 비동기 상태를 Other에서 전송합니다. 전송 후 기타 항목이 비어 있습니다.

promise::promise 생성자

promise 개체를 생성합니다.

promise();
template <class Alloc>
promise(allocator_arg_t, const Alloc& Al);
promise(promise&& Other) noexcept;

매개 변수

Al
메모리 할당자입니다. 할당자에 대한 자세한 내용은 할당자를 참조 <하세요>.

기타
promise 개체입니다.

설명

첫 번째 생성자는 빈 promise 개체를 생성합니다.

두 번째 생성자는 빈 promise 개체를 생성하고 메모리 할당에 Al을 사용합니다.

세 번째 생성자는 개체를 promise 생성하고 연결된 비동기 상태를 Other에서 전송하고 기타를 비워 둡니다.

promise::set_exception

promise 개체의 결과로 예외를 원자 단위로 저장하고 연결된 비동기 상태ready로 설정합니다.

void set_exception(exception_ptr Exc);

매개 변수

Exc
이 메서드가 예외 결과로 저장한 exception_ptr입니다.

설명

promise 개체에 연결된 비동기 상태가 없는 경우 이 메서드는 오류 코드가 no_statefuture_error를 throw합니다.

set_exception, set_exception_at_thread_exit, set_value 또는 set_value_at_thread_exit가 동일한 연관 비동기 상태의 promise 개체에 대해 이미 호출된 경우 이 메서드는 오류 코드가 promise_already_satisfiedfuture_error를 throw합니다.

이 메서드의 결과로 연결된 비동기 상태에서 차단된 모든 스레드의 차단은 해제됩니다.

promise::set_exception_at_thread_exit

promise의 결과를 원자 단위로 예외로 설정하여 현재 스레드의 스레드 로컬 개체가 모두 소멸된 후에만 통지를 전달합니다.

void set_exception_at_thread_exit(exception_ptr Exc);

매개 변수

Exc
이 메서드가 예외 결과로 저장한 exception_ptr입니다.

설명

promise 개체에 연결된 비동기 상태가 없는 경우 이 메서드는 오류 코드가 no_statefuture_error를 throw합니다.

set_exception, set_exception_at_thread_exit, set_value 또는 set_value_at_thread_exit가 동일한 연관 비동기 상태의 promise 개체에 대해 호출된 경우 이 메서드는 오류 코드가 promise_already_satisfiedfuture_error를 throw합니다.

set_exception 달리 이 메서드는 현재 스레드의 모든 스레드 로컬 개체가 제거될 때까지 연결된 비동기 상태를 준비 상태로 설정하지 않습니다. 일반적으로 연결된 비동기 상태에서 차단된 스레드는 현재 스레드가 종료될 때까지 차단 해제되지 않습니다.

promise::set_value

promise 개체의 결과로 값을 원자 단위로 저장하고 연결된 비동기 상태ready로 설정합니다.

void promise::set_value(const Ty& Val);
void promise::set_value(Ty&& Val);
void promise<Ty&>::set_value(Ty& Val);
void promise<void>::set_value();

매개 변수

Val
결과로 저장할 값입니다.

설명

promise 개체에 연결된 비동기 상태가 없는 경우 이 메서드는 오류 코드가 no_statefuture_error를 throw합니다.

set_exception, set_exception_at_thread_exit, set_value 또는 set_value_at_thread_exit가 동일한 연관 비동기 상태의 promise 개체에 대해 이미 호출된 경우 이 메서드는 오류 코드가 promise_already_satisfiedfuture_error를 throw합니다.

이 메서드의 결과로 연결된 비동기 상태에서 차단된 모든 스레드의 차단은 해제됩니다.

첫 번째 메서드는 Val이 연결된 비동기 상태로 복사될 때 throw되는 예외도 throw합니다. 이 경우 연결된 비동기 상태가 준비 상태로 설정되지 않습니다.

또한 두 번째 메서드는 Val이 연결된 비동기 상태로 이동할 때 throw되는 예외를 throw합니다. 이 경우 연결된 비동기 상태가 준비 상태로 설정되지 않습니다.

부분 특수화promise<Ty&>의 경우 저장된 값은 실제로 Val대한 참조입니다.

특수화 promise<void>에 대해 저장된 값은 없습니다.

promise::set_value_at_thread_exit

promise 개체의 결과로 값을 원자 단위로 저장합니다.

void promise::set_value_at_thread_exit(const Ty& Val);
void promise::set_value_at_thread_exit(Ty&& Val);
void promise<Ty&>::set_value_at_thread_exit(Ty& Val);
void promise<void>::set_value_at_thread_exit();

매개 변수

Val
결과로 저장할 값입니다.

설명

promise 개체에 연결된 비동기 상태가 없는 경우 이 메서드는 오류 코드가 no_statefuture_error를 throw합니다.

set_exception, set_exception_at_thread_exit, set_value 또는 set_value_at_thread_exit가 동일한 연관 비동기 상태의 promise 개체에 대해 호출된 경우 이 메서드는 오류 코드가 promise_already_satisfiedfuture_error를 throw합니다.

반면 set_value, 연결된 비동기 상태는 현재 스레드의 모든 스레드 로컬 개체가 제거될 때까지 준비되도록 설정되지 않습니다. 일반적으로 연결된 비동기 상태에서 차단된 스레드는 현재 스레드가 종료될 때까지 차단 해제되지 않습니다.

첫 번째 메서드는 Val이 연결된 비동기 상태로 복사될 때 throw되는 예외도 throw합니다.

또한 두 번째 메서드는 Val이 연결된 비동기 상태로 이동할 때 throw되는 예외를 throw합니다.

부분 특수화promise<Ty&>의 경우 저장된 값은 Val에 대한 참조입니다.

특수화 promise<void>에 대해 저장된 값은 없습니다.

promise::swap

이 promise 개체의 연결된 비동기 상태를 지정한 개체의 연결된 비동기 상태와 교환합니다.

void swap(promise& Other) noexcept;

매개 변수

기타
promise 개체입니다.

참고 항목

헤더 파일 참조