# Condvar

`import { Condvar } from "destack:sync";`

Condition variable paired with a mutex.

```ds title="Condvar"
export class Condvar {
    constructor();
    wait<T>(guard: MutexGuard<T>): MutexGuard<T>;
    waitWhile<T>(guard: MutexGuard<T>, condition: (&'a readonly T) => boolean): MutexGuard<T>;
    notifyOne(): void;
    notifyAll(): void;
}
```

[language/library/src/sync/condvar.ds:6:31](https://github.com/destack-sh/destack/blob/main/language/library/src/sync/condvar.ds#L6-L31)

## Members

### `constructor()`

Create a condition variable.

### `wait<T>(guard: MutexGuard<T>): MutexGuard<T>`

Wait and reacquire the mutex before returning.

### `waitWhile<T>(guard: MutexGuard<T>, condition: (&'a readonly T) => boolean): MutexGuard<T>`

Wait while `condition` returns true.

### `notifyOne(): void`

Wake one waiting worker.

### `notifyAll(): void`

Wake all waiting workers.
