Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 20, 2024
1 parent 1aed0b6 commit 8b1986a
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions readme.md
Expand Up @@ -44,23 +44,6 @@ console.log(await getPort({port: portNumbers(3000, 3100)}));
// Will use any port from 3000 to 3100, otherwise fall back to a random port
```

Use the `clearLockedPorts()` to clear the internal cache of locked ports.

```js
import getPort, {clearLockedPorts} from 'get-port';

console.log(await getPort({prot: [3000, 3001, 3002]}));
//=> 3000

console.log(await getPort({prot: [3000, 3001, 3002]}));
//=> 3001

// If you want the results to not be affected by previous calls, clear the cache.
clearLockedPorts();
console.log(await getPort({prot: [3000, 3001, 3002]}));
//=> 3000
```

## API

### getPort(options?)
Expand Down Expand Up @@ -117,7 +100,25 @@ Clear the internal cache of locked ports.

This can be useful when you want the results to be unaffected by previous calls.

Please note that clearing the cache could cause race conditions.
Please note that clearing the cache could cause [race conditions](#beware).

```js
import getPort, {clearLockedPorts} from 'get-port';

const port = [3000, 3001, 3002];

console.log(await getPort({port}));
//=> 3000

console.log(await getPort({port}));
//=> 3001

// If you want the results to be unaffected by previous calls, clear the cache.
clearLockedPorts();

console.log(await getPort({port}));
//=> 3000
```

## Beware

Expand Down

0 comments on commit 8b1986a

Please sign in to comment.