# Poco

# template < class ResultType, class ArgType, class OwnerType, class StarterType = ActiveStarter < OwnerType >>

# class ActiveMethod

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

## Description

An active method is a method that, when called, executes in its own thread. ActiveMethod's take exactly one argument and can return a value. To pass more than one argument to the method, use a struct. The following example shows how to add an ActiveMethod to a class:

    class ActiveObject
    {
    public:
        ActiveObject():
            exampleActiveMethod(this, &ActiveObject::exampleActiveMethodImpl)
        {
        }

        ActiveMethod<std::string, std::string, ActiveObject> exampleActiveMethod;

    protected:
        std::string exampleActiveMethodImpl(const std::string& arg)
        {
            ...
        }
    };

And following is an example that shows how to invoke an ActiveMethod.

    ActiveObject myActiveObject;
    ActiveResult<std::string> result = myActiveObject.exampleActiveMethod("foo");
    ...
    result.wait();
    std::cout << result.data() << std::endl;

The way an ActiveMethod is started can be changed by passing a StarterType template argument with a corresponding class. The default ActiveStarter starts the method in its own thread, obtained from a thread pool.

For an alternative implementation of StarterType, see ActiveDispatcher.

For methods that do not require an argument or a return value, the Void class can be used.

## Member Summary

Member Functions: operator (), operator =, swap

## Types Aliases

### ActiveResultType

using ActiveResultType = ActiveResult < ResultType >;

### ActiveRunnableType

using ActiveRunnableType = ActiveRunnable < ResultType, ArgType, OwnerType >;

### Callback

using Callback = ResultType (OwnerType::*)(const ArgType &);

## Constructors

### ActiveMethod

ActiveMethod() = delete;

### ActiveMethod

ActiveMethod(
const ActiveMethod & other
);

### ActiveMethod

ActiveMethod(
OwnerType * pOwner,
Callback method
);

Creates an ActiveMethod object.

## Member Functions

### operator ()

ActiveResultType operator () (
const ArgType & arg
);

Invokes the ActiveMethod.

### operator =

ActiveMethod & operator = (
const ActiveMethod & other
);

### swap

void swap(
ActiveMethod & other
) noexcept;