# AsyncRwLock

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

Asynchronous reader-writer lock.

```ds title="AsyncRwLock"
export class AsyncRwLock<T> {
    value: T;
    constructor(value: T);
    read(): Task<AsyncRwLockReadGuard<T>>;
    tryRead(): AsyncRwLockReadGuard<T> | undefined;
    write(): Task<AsyncRwLockWriteGuard<T>>;
    tryWrite(): AsyncRwLockWriteGuard<T> | undefined;
    getExclusive(): &exclusive T;
    intoInner(): T;
}
```

[language/library/src/async/rwlock.ds:8:46](https://github.com/destack-sh/destack/blob/main/language/library/src/async/rwlock.ds#L8-L46)

## Members

### `value: T`

The protected value.

### `constructor(value: T)`

Create an async reader-writer lock protecting `value`.

### `read(): Task<AsyncRwLockReadGuard<T>>`

Lock this value for shared reading.

### `tryRead(): AsyncRwLockReadGuard<T> | undefined`

Try to lock this value for shared reading.

### `write(): Task<AsyncRwLockWriteGuard<T>>`

Lock this value for exclusive writing.

### `tryWrite(): AsyncRwLockWriteGuard<T> | undefined`

Try to lock this value for exclusive writing.

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

Borrow the protected value without locking.

### `intoInner(): T`

Consume this lock and return the protected value.
