template <typename T, typename... Methods>

class SyncProxy

Defined at line 62 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

|SyncProxy| is an ergonomic wrapper over |TestDispatcherBound| that simplifies

the |SyncCall| syntax into direct function calls:

auto r = sync_proxy.Foo(arg);

is equivalent to

auto r = test_dispatcher_bound.SyncCall(

&T

::Foo, arg);

To use it, suppose there's a |Background| class with two methods |Foo|, |Bar|.

We will choose |BackgroundSyncProxy| as the name of the sync proxy class.

First tell the library about those methods using this macro:

ASYNC_PATTERNS_DEFINE_SYNC_METHOD(BackgroundSyncProxy, Foo);

ASYNC_PATTERNS_DEFINE_SYNC_METHOD(BackgroundSyncProxy, Bar);

Then define |BackgroundSyncProxy| as the following type alias:

using BackgroundSyncProxy = async_patterns::SyncProxy

<

Background,

ASYNC_PATTERNS_ADD_SYNC_METHOD(BackgroundSyncProxy, Background, Foo),

ASYNC_PATTERNS_ADD_SYNC_METHOD(BackgroundSyncProxy, Background, Bar)

>;

After that, you may use |BackgroundSyncProxy| like so:

// The sync proxy supports the same construction API as |TestDispatcherBound|.

BackgroundSyncProxy background(dispatcher);

background.emplace(constructor_args);

// But instead of |SyncCall|, you can directly call |Foo| and |Bar|.

auto return_value = background.Foo(...);

auto return_value = background.Bar(...);

|SyncProxy| methods cannot be overloaded, or templated. If one of your member functions

uses those features, you may call it through dispatcher bound:

background

.dispatcher_bound()

.SyncCall

<void

(int, int)>(

&Background

::OverloadedFunction, 1, 2);

Public Methods

template <typename... Args>
void SyncProxy<T, Methods...> (async_dispatcher_t * dispatcher, std::in_place_t , Args &&... args)

Constructs a sync proxy with a |TestDispatcherBound| holding an object.

See |async_patterns::TestDispatcherBound| for more information.

Defined at line 71 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

void SyncProxy<T, Methods...> (async_dispatcher_t * dispatcher)

Constructs a sync proxy with an empty |TestDispatcherBound|.

Defined at line 75 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

template <typename T2 = T, typename... Args>
void emplace (Args &&... args)

Constructs an object inside the |TestDispatcherBound|.

See |async_patterns::DispatcherBound

<T

>::emplace| for more information.

Defined at line 81 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

void reset ()

If |has_value|, asynchronously destroys the managed |T| on a task

posted to the dispatcher.

See |async_patterns::DispatcherBound

<T

>::reset| for more information.

Defined at line 89 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

bool has_value ()

Returns if this object holds an instance of |T|.

See |async_patterns::DispatcherBound

<T

>::reset| for more information.

Defined at line 94 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h

async_patterns::TestDispatcherBound<T> & dispatcher_bound ()

Returns a reference to the underlying |TestDispatcherBound|.

Defined at line 97 of file ../../sdk/lib/async_patterns/testing/next/cpp/sync_proxy.h