Skip to content

Commit

Permalink
feat(daemon): Node socket server exposes assigned port
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored and kumavis committed Feb 13, 2024
1 parent 5ce98ee commit d0a9168
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ export const makeSocketPowers = ({ net }) => {
void writeTo.next({ reader, writer, closed });
});

return readFrom;
const port = await listening;

return harden({
port,
connections: readFrom,
});
};

/**
Expand All @@ -228,7 +233,7 @@ export const makeSocketPowers = ({ net }) => {
serveListener(
server =>
new Promise(resolve =>
server.listen(port, host, () => resolve(undefined)),
server.listen(port, host, () => resolve(server.address().port)),
),
cancelled,
);
Expand All @@ -238,8 +243,8 @@ export const makeSocketPowers = ({ net }) => {
* @param {string} args.path
* @param {Promise<never>} args.cancelled
*/
const servePath = async ({ path, cancelled }) =>
serveListener(server => {
const servePath = async ({ path, cancelled }) => {
const { connections } = await serveListener(server => {
return new Promise((resolve, reject) =>
server.listen({ path }, error => {
if (error) {
Expand All @@ -255,6 +260,8 @@ export const makeSocketPowers = ({ net }) => {
}),
);
}, cancelled);
return connections;
};

return { servePort, servePath };
};
Expand Down

0 comments on commit d0a9168

Please sign in to comment.