mirror of
https://github.com/denoland/deno.git
synced 2024-10-31 09:14:20 -04:00
21 lines
460 B
TypeScript
21 lines
460 B
TypeScript
|
import { assert } from "../testing/asserts.ts";
|
||
|
|
||
|
function* portIterator(): IterableIterator<number> {
|
||
|
// use 55001 ~ 65535 (rest (49152~55000) are for cli/js)
|
||
|
let i = 55001;
|
||
|
while (true) {
|
||
|
yield i;
|
||
|
i++;
|
||
|
if (i > 65535) {
|
||
|
i = 55001;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
const it = portIterator();
|
||
|
/** Obtain (maybe) safe port number for net tests */
|
||
|
export function randomPort(): number {
|
||
|
const { value } = it.next();
|
||
|
assert(value != null);
|
||
|
return value;
|
||
|
}
|