# AsyncMutex

`import { AsyncMutex } from "destack:async";`

Asynchronous mutual exclusion lock.

```ds title="AsyncMutex"
export class AsyncMutex<T> {
    value: T;
    constructor(value: T);
    lock(): Task<AsyncMutexGuard<T>>;
    tryLock(): AsyncMutexGuard<T> | undefined;
    getExclusive(): &exclusive T;
    intoInner(): T;
}
```

[language/library/src/async/mutex.ds:8:36](https://github.com/destack-sh/destack/blob/main/language/library/src/async/mutex.ds#L8-L36)

## Members

### `value: T`

The protected value.

### `constructor(value: T)`

Create an async mutex protecting `value`.

### `lock(): Task<AsyncMutexGuard<T>>`

Lock this mutex by suspending the current task.

### `tryLock(): AsyncMutexGuard<T> | undefined`

Try to lock this mutex without suspending.

### `getExclusive(): &exclusive T`

Borrow the protected value without locking.

### `intoInner(): T`

Consume this mutex and return the protected value.
