Skip to content

Commit

Permalink
fixup! docs: Add Component Locking section to README
Browse files Browse the repository at this point in the history
  • Loading branch information
lmars committed Aug 29, 2023
1 parent d523c1d commit 644501d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ for (const lock of allLocks) {

### Acquire

`space.locks.acquire` initialises a lock request, adds it to the `locks` field of presence message extras, and calls `presence.update`.
`space.locks.acquire` sends a request to acquire a lock using presence.

It returns a Promise which resolves once `presence.update` resolves.
It returns a Promise which resolves once the presence request has been sent.

```javascript
const req = await space.locks.acquire(id);
Expand All @@ -377,9 +377,9 @@ It throws an error if a lock request already exists for the given identifier wit

### Release

`space.locks.release` releases a previously requested lock by removing it from the `locks` field of presence message extras, and calls `presence.update`.
`space.locks.release` releases a previously requested lock by removing it from presence.

It returns a Promise which resolves once `presence.update` resolves.
It returns a Promise which resolves once the presence request has been sent.

```javascript
await space.locks.release(id);
Expand All @@ -406,7 +406,7 @@ space.locks.subscribe('update', ({ member, request }) => {

Such changes occur when:

- a `PENDING` request transitions to `LOCKED` (i.e. the requesting member now holds the lock)
- a `PENDING` request transitions to `UNLOCKED` (i.e. the requesting member does not hold the lock since another member already does)
- a `LOCKED` request transitions to `UNLOCKED` (i.e. the lock was either released or invalidated by a concurrent request which took precedence)
- an `UNLOCKED` request transitions to `LOCKED` (i.e. the requesting member reacquired a lock)
- a `PENDING` request transitions to `LOCKED` because the requesting member now holds the lock
- a `PENDING` request transitions to `UNLOCKED` because the requesting member does not hold the lock since another member already does
- a `LOCKED` request transitions to `UNLOCKED` because the lock was either released or invalidated by a concurrent request which took precedence
- an `UNLOCKED` request transitions to `LOCKED` because the requesting member reacquired a lock

0 comments on commit 644501d

Please sign in to comment.