# async_patterns::Receiver

`#include <receiver.h>`

A \|Receiver\| is a hub for an owner object to asynchronously receive messages and calls from other objects living on different async dispatchers.

## Summary

A \|Receiver\| should be embedded as a member variable of an owner object which wishes to receive messages. The receiver will silently discard pending messages when it destructs, typically as part of its parent.

The \|Receiver\| is thread-unsafe, and must be used and managed from a [synchronized dispatcher](https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/thread-safe-async#synchronized-dispatcher).

Calls posted to the same \|Receiver\| will be processed in the order they are made, regardless which \|Function\|s and \|Callback\|s they are made from.

Calls posted to different \|Receiver\|s living on the same dispatcher are not guaranteed to be processed before or after one another.

### Inheritance

Inherits from: async_patterns::internal::ReceiverBase

| ### Constructors and Destructors ||
|---|---|
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a4bd2d2df3092ba8c3232d23047adb011(Owner *owner, async_dispatcher_t *dispatcher)` Constructs a receiver. ||
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a7de4ee11cb992ce9127b8a897b6749cf(const https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &)` ||
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a607ee8db4b1edbfea820b66bd5c55a3f(https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &&)` ||

| ### Public functions ||
|---|---|
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1aaf38759799c0b08d2a72cddd3b487a7e(Member Owner::*member)` | `auto` Mints a \|Callback\| object that holds a capability to send \|Args\| to the owner object once. |
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a4cde50df217e9a29f636ddff0f1128ab(StatelessLambda callable)` | `auto` Mints a \|Callback\| object that holds a capability to send \|Args\| to the owner object once. |
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1abc74e98353ac964794b3f6ef34fd3837(Member Owner::*member)` | `auto` Mints a \|Function\| object that holds a capability to send \|Args\| to the owner object repeatedly. |
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1afbeb4bf7482e82071561d033d9d409cb(StatelessLambda callable)` | `auto` Mints a \|Function\| object that holds a capability to send \|Args\| to the owner object repeatedly. |
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a959371f8d4535e7f4730b6d89cbcda51(const https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &)=delete` | `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &` |
| `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver_1a3889775c0a85e05c56c68520a9cd98fb(https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &&)=delete` | `https://fuchsia.dev/reference/cpp/other/singletonasync-patterns/receiver#singletonasync__patterns_1_1_receiver &` |

## Public functions

### Once

```c++
auto Once(
  Member Owner::*member
)
```
Mints a \|Callback\| object that holds a capability to send \|Args\| to the owner object once.

When the resulting \|Callback\| is invoked on some other thread, \|member\| is scheduled to be called on the \|dispatcher\|.

\|member\| should be a pointer to member function. It should have the function signature `void Owner::SomeMember(Args...)` where Args are some number of arguments.

### Once

```c++
auto Once(
  StatelessLambda callable
)
```
Mints a \|Callback\| object that holds a capability to send \|Args\| to the owner object once.

When the resulting \|Callback\| is invoked on some other thread, \|callable\| is scheduled to be called on the \|dispatcher\|.

\|callable\| should be a lambda without any captures. It should have the function signature `void(Owner*, Args...)` where Args are some number of arguments.

### Receiver

```c++
 Receiver(
  Owner *owner,
  async_dispatcher_t *dispatcher
)
```
Constructs a receiver.

\|owner\| should be `this`. \|dispatcher\| should be the dispatcher that the current task is running on, and where \|Owner\| typically lives.

### Receiver

```c++
 Receiver(
  const Receiver &
)=delete
```

### Receiver

```c++
 Receiver(
  Receiver &&
)=delete
```

### Repeating

```c++
auto Repeating(
  Member Owner::*member
)
```
Mints a \|Function\| object that holds a capability to send \|Args\| to the owner object repeatedly.

When the resulting \|Function\| is invoked on some other thread, \|member\| is scheduled to be called on the \|dispatcher\|.

\|member\| should be a pointer to member function. It should have the function signature `void Owner::SomeMember(Args...)` where Args are some number of arguments.

### Repeating

```c++
auto Repeating(
  StatelessLambda callable
)
```
Mints a \|Function\| object that holds a capability to send \|Args\| to the owner object repeatedly.

When the resulting \|Function\| is invoked on some other thread, \|callable\| is scheduled to be called on the \|dispatcher\|.

\|callable\| should be a lambda without any captures. It should have the function signature `void(Owner*, Args...)` where Args are some number of arguments.

### operator=

```c++
Receiver & operator=(
  const Receiver &
)=delete
```

### operator=

```c++
Receiver & operator=(
  Receiver &&
)=delete
```