Skip to content

Commit

Permalink
Add docs of Semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed May 7, 2023
1 parent 7016b40 commit 7e68d46
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ assertEquals(await stack.pop(), 2);
assertEquals(await stack.pop(), 1);
```

### Semaphore

A semaphore that allows a limited number of concurrent executions of an
operation.

```ts
import { Semaphore } from "./semaphore.ts";

const sem = new Semaphore(5);
const worker = () => {
return sem.lock(async () => {
// do something
});
};
await Promise.all([...Array(10)].map(() => worker()));
```

### promiseState

`promiseState` is used to determine the state of the promise. Mainly for testing
Expand Down

0 comments on commit 7e68d46

Please sign in to comment.