Skip to content

Commit

Permalink
feat: add toString method to Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
antho-bunny committed Aug 28, 2024
1 parent 99ea60e commit f0a61d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/purple-tips-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bunny.net/edgescript-sdk": minor
---

Add a toString method to TCP Listener
2 changes: 1 addition & 1 deletion libs/bunny-sdk/src/net/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ServeHandler = {} & unknown;
*/
function serve(listener: { port: number; hostname: string; }, handler: ServerHandler): ServeHandler;
function serve(listener: TcpListener, handler: ServerHandler): ServeHandler;
function serve(listener: TcpListener | { port: number; hostname: string; }, handler: ServerHandler): ServeHandler {
function serve(listener: TcpListener | { port: number; hostname: string; } | ServerHandler, handler: ServerHandler): ServeHandler {
const platform = internal_getPlatform();

const listenerUnion = Tcp.isTcpListener(listener) ? listener : Tcp.unstable_new();
Expand Down
7 changes: 7 additions & 0 deletions libs/bunny-sdk/src/net/tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export function unstable_local_addr(tcp: TcpListener): SocketAddr.SocketAddr {
return tcp.addr;
}

/**
* Format the associated [TcpListener] to a String
*/
export function toString(tcp: TcpListener): string {
return `${SocketAddr.ip(tcp.addr)}:${SocketAddr.port(tcp.addr)}`;
}

/**
* Create a new [TcpListener].
*/
Expand Down

0 comments on commit f0a61d8

Please sign in to comment.