# libsync::Completion

`#include <completion.h>`

C++ wrapper for a completion object, \|sync_completion_t\|.

## Summary

A \|Completion\| is a synchronization primitive that allows for one or more threads to wait for a signal from another thread.

See for full details.

This class is thread-safe.

| ### Public functions ||
|---|---|
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1af3da51082d8ffaa196a61adddf405a23()` | `void` Resets the completion object's signaled state to unsignaled. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1aac028b0a666e82c1e368f8bca0db2a3b()` | `void` Awakens all waiters on the completion, and marks it as signaled. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1ac35f73bd19622a8540fb61c1a11ab6fc()` | `void` Waits until woken by a call to \|Signal\| or if the completion has already been signaled. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1ac38044f5663fd8a5c5c536daf50744ea(https://fuchsia.dev/reference/cpp/class/zx/duration#classzx_1_1duration timeout)` | `zx_status_t` Returns ZX_ERR_TIMED_OUT if \|timeout\| elapses, and ZX_OK if woken by a call to \|Signal\| or if the completion has already been signaled. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1a818100ecb2ae41ca0d955435d52c128d(https://fuchsia.dev/reference/cpp/class/zx/basic-time#classzx_1_1basic__time deadline)` | `zx_status_t` Returns ZX_ERR_TIMED_OUT if \|deadline\| elapses, and ZX_OK if woken by a call to \|Signal\| or if the completion has already been signaled. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1a991a4fafe306554f9c3584f27ca9d34c()` | `sync_completion_t *` Gets the underlying \|sync_completion_t\|. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1a3bac334b106c2dd7705a523d4f15d9ae() const ` | `const sync_completion_t *` Gets the underlying \|sync_completion_t\|. |
| `https://fuchsia.dev/reference/cpp/class/libsync/completion#classlibsync_1_1_completion_1a144099ebe85086a9f81bf708f3af61df() const ` | `bool` Returns true iff the completion object has been signaled. |

## Public functions

### Reset

```c++
void Reset()
```
Resets the completion object's signaled state to unsignaled.

### Signal

```c++
void Signal()
```
Awakens all waiters on the completion, and marks it as signaled.

Waits after this call but before a reset of the completion will also see the signal and immediately return.

### Wait

```c++
void Wait()
```
Waits until woken by a call to \|Signal\| or if the completion has already been signaled.

### Wait

```c++
zx_status_t Wait(
  zx::duration timeout
)
```
Returns ZX_ERR_TIMED_OUT if \|timeout\| elapses, and ZX_OK if woken by a call to \|Signal\| or if the completion has already been signaled.

### Wait

```c++
zx_status_t Wait(
  zx::time deadline
)
```
Returns ZX_ERR_TIMED_OUT if \|deadline\| elapses, and ZX_OK if woken by a call to \|Signal\| or if the completion has already been signaled.

### get

```c++
sync_completion_t * get()
```
Gets the underlying \|sync_completion_t\|.

### get

```c++
const sync_completion_t * get() const 
```
Gets the underlying \|sync_completion_t\|.

### signaled

```c++
bool signaled() const 
```
Returns true iff the completion object has been signaled.