Skip to content

Commit

Permalink
chore(daemon): improve types for SocketPowers
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis committed Feb 13, 2024
1 parent 82c45af commit cb84421
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 3 additions & 11 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ export const makeSocketPowers = ({ net }) => {
});
};

/**
* @param {object} args
* @param {number} args.port
* @param {string} [args.host]
* @param {Promise<never>} args.cancelled
*/
/** @type {import('./types.js').SocketPowers['servePort']} */
const servePort = async ({ port, host = '0.0.0.0', cancelled }) =>
serveListener(
server =>
Expand All @@ -238,6 +233,7 @@ export const makeSocketPowers = ({ net }) => {
cancelled,
);

/** @type {import('./types.js').SocketPowers['connectPort']} */
const connectPort = ({ port, host, cancelled }) =>
new Promise((resolve, reject) => {
const conn = net.connect(port, host, err => {
Expand All @@ -256,11 +252,7 @@ export const makeSocketPowers = ({ net }) => {
});
});

/**
* @param {object} args
* @param {string} args.path
* @param {Promise<never>} args.cancelled
*/
/** @type {import('./types.js').SocketPowers['servePath']} */
const servePath = async ({ path, cancelled }) => {
const { connections } = await serveListener(server => {
return new Promise((resolve, reject) =>
Expand Down
15 changes: 11 additions & 4 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,22 @@ export type PetStorePowers = {
};

export type SocketPowers = {
servePath: (args: {
path: string;
servePort: (args: {
port: number;
host?: string;
cancelled: Promise<never>;
}) => Promise<AsyncIterableIterator<Connection>>;
servePort: (args: {
}) => Promise<{
port: number;
connections: Reader<Connection>;
}>;
connectPort: (args: {
port: number;
host?: string;
cancelled: Promise<never>;
}) => Promise<Connection>;
servePath: (args: {
path: string;
cancelled: Promise<never>;
}) => Promise<AsyncIterableIterator<Connection>>;
};

Expand Down

0 comments on commit cb84421

Please sign in to comment.