# Poco

# template < class RT >

# class ActiveResult

Library: Foundation
Package: Threading
Header: Poco/ActiveResult.h

## Description

Creates an ActiveResultHolder. Pauses the caller until the result becomes available. Waits up to the specified interval for the result to become available. Returns true if the result became available, false otherwise. Waits up to the specified interval for the result to become available. Throws a TimeoutException if the result did not became available. Notifies the invoking thread that the result became available. Returns true if the active method failed (and threw an exception). Information about the exception can be obtained by calling error(). If the active method threw an exception, a textual representation of the exception is returned. An empty string is returned if the active method completed successfully. If the active method threw an exception, a clone of the exception object is returned, otherwise null. Sets the exception. Sets the exception. This class holds the result of an asynchronous method invocation (see class ActiveMethod). It is used to pass the result from the execution thread back to the invocation thread.

## Member Summary

Member Functions: available, data, error, exception, failed, notify, operator =, swap, tryWait, wait

## Types Aliases

### ActiveResultHolderType

using ActiveResultHolderType = ActiveResultHolder < ResultType >;

### ResultType

using ResultType = RT;

## Constructors

### ActiveResult

ActiveResult() = delete;

### ActiveResult

ActiveResult(
ActiveResultHolderType * pHolder
);

Creates the active result. For internal use only.

### ActiveResult

ActiveResult(
const ActiveResult & result
);

Copy constructor.

## Destructor

### ~ActiveResult

~ActiveResult();

Destroys the result.

## Member Functions

### available

bool available() const;

Returns true if a result is available.

### data

ResultType & data() const;

Returns a reference to the result data.

### data

void data(
ResultType * pValue
);

### data

ResultType & data();

Returns a non-const reference to the result data. For internal use only.

### error

std::string error() const;

If the active method threw an exception, a textual representation of the exception is returned. An empty string is returned if the active method completed successfully.

### error

void error(
const std::string & msg
);

Sets the failed flag and the exception message.

### error

void error(
const Exception & exc
);

Sets the failed flag and the exception message.

### exception

Exception * exception() const;

If the active method threw an exception, a clone of the exception object is returned, otherwise null.

### failed

bool failed() const;

Returns true if the active method failed (and threw an exception). Information about the exception can be obtained by calling error().

### notify

void notify();

Notifies the invoking thread that the result became available. For internal use only.

### operator =

ActiveResult & operator = (
const ActiveResult & result
);

Assignment operator.

### swap

void swap(
ActiveResult & result
) noexcept;

### tryWait

bool tryWait(
long milliseconds
);

Waits up to the specified interval for the result to become available. Returns true if the result became available, false otherwise.

### wait

void wait();

Pauses the caller until the result becomes available.

### wait

void wait(
long milliseconds
);

Waits up to the specified interval for the result to become available. Throws a TimeoutException if the result did not became available.