feat(smartnetwork): Add exclude option to findFreePort and skip excluded ports during search
This commit is contained in:
14
readme.md
14
readme.md
@@ -99,6 +99,19 @@ const findFreePort = async () => {
|
||||
// Find a random free port in range (useful to avoid port conflicts)
|
||||
const randomPort = await network.findFreePort(3000, 3100, { randomize: true });
|
||||
console.log(`🎲 Random free port: ${randomPort}`);
|
||||
|
||||
// Exclude specific ports from the search
|
||||
const portWithExclusions = await network.findFreePort(3000, 3100, {
|
||||
exclude: [3000, 3001, 3005] // Skip these ports even if they're free
|
||||
});
|
||||
console.log(`🚫 Free port (excluding specific ports): ${portWithExclusions}`);
|
||||
|
||||
// Combine randomize with exclude options
|
||||
const randomWithExclusions = await network.findFreePort(3000, 3100, {
|
||||
randomize: true,
|
||||
exclude: [3000, 3001, 3005]
|
||||
});
|
||||
console.log(`🎲🚫 Random free port (with exclusions): ${randomWithExclusions}`);
|
||||
};
|
||||
```
|
||||
|
||||
@@ -333,6 +346,7 @@ interface SmartNetworkOptions {
|
||||
|
||||
interface IFindFreePortOptions {
|
||||
randomize?: boolean; // If true, returns a random free port instead of the first one
|
||||
exclude?: number[]; // Array of port numbers to exclude from the search
|
||||
}
|
||||
|
||||
interface Hop {
|
||||
|
Reference in New Issue
Block a user