template <typename T>

class TestDispatcherBound

Defined at line 25 of file ../../sdk/lib/async_patterns/testing/cpp/dispatcher_bound.h

|TestDispatcherBound| adds the ability to issue synchronous calls on top of

|DispatcherBound|. Synchronous test code may use this class instead of

manually running an event loop.

See |async_patterns::DispatcherBound| for general information.

See |async_patterns::SyncProxy| which uses this class to manage a thread-unsafe

object and expose synchronous wrapper methods for every member method you specify.

Public Methods

template <typename Member, typename... Args>
auto AsyncCall (Member T::* member, Args &&... args)

Refer to |DispatcherBound

<T

>::AsyncCall| for documentation.

This test version of |AsyncCall| adds the ability to encapsulate the result

of the call into a |std::future

<R

>|. This way, tests can synchronously block

on that future, leading to more direct code:

std::future

<std

::string> fut = some_dispatcher_bound

.AsyncCall(

&Object

::GetSomeString)

.ToFuture();

Defined at line 50 of file ../../sdk/lib/async_patterns/testing/cpp/dispatcher_bound.h

template <typename Callable, typename... Args>
auto SyncCall (Callable && callable, Args &&... args)

Schedules an asynchronous |callable| on |dispatcher| with |args| and then

block the caller until the asynchronous call is processed, returning the

result of the asynchronous call.

|callable| should take |T*| as the first argument, followed by optionally

|Args| if any. A special case of |callable| is a pointer-to-member, e.g.

|

&T

::SomeFunction|. Example:

struct Foo {

int Add(int a, int b) { return a + b; }

};

async_patterns::TestDispatcherBound

<Foo

> object{foo_loop.dispatcher()};

int result = object.SyncCall(

&Object

::Add, 1, 2); // result == 3

If |Object::Add| is an overloaded member function, you may disambiguate it

by spelling out its signature:

int result = object.SyncCall

<int

(int, int)>(

&Object

::Add, 1, 2);

General callables are also supported. The provided callable can safely

capture state without data races, because the current thread will be

suspended while the dispatcher thread is accessing the captures. However,

if you capture a pointer or reference, be careful to not let them escape to

the wrapped object. When in doubt, only use the captured data inside the

lambda scope:

int result = object.SyncCall([

&

] (Foo* foo) {

return foo->Add(1, 2);

}); // result == 3

If |callable| returns |void|, |SyncCall| will still block until the

|callable| finishes executing on the target |dispatcher|. To schedule a

fire-and-forget call, use |AsyncCall|.

Defined at line 98 of file ../../sdk/lib/async_patterns/testing/cpp/dispatcher_bound.h

template <typename Member, typename... Args>
auto SyncCall (Member T::* member, Args &&... args)

Defined at line 122 of file ../../sdk/lib/async_patterns/testing/cpp/dispatcher_bound.h

Records