Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom-timeout-values-for-requester-method #299

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/NWCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export type Nip47PayResponse = {
preimage: string;
};

type Nip47TimeoutValues = {
replyTimeout?: number;
publishTimeout?: number;
};

export type Nip47MultiPayInvoiceRequest = {
invoices: (Nip47PayInvoiceRequest & WithOptionalId)[];
};
Expand Down Expand Up @@ -544,6 +549,7 @@ export class NWCClient {
"get_info",
{},
(result) => !!result.methods,
{ replyTimeout: 10000 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally you also wanted to be able to customize this on a per-request basis right? but I guess this is ok.

I would probably also apply this smaller timeout to other non-payment requests (get balance, get budget, list transactions, etc.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll effect these

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rolznz done. I thought of making a shorter reply timeout the default in the Nip47Request method but it seems there are as much payment related requests as non-payment. So this is good

);
return result;
} catch (error) {
Expand All @@ -558,6 +564,7 @@ export class NWCClient {
"get_budget",
{},
(result) => result !== undefined,
{ replyTimeout: 10000 },
);
return result;
} catch (error) {
Expand All @@ -572,6 +579,7 @@ export class NWCClient {
"get_balance",
{},
(result) => result.balance !== undefined,
{ replyTimeout: 10000 },
);
return result;
} catch (error) {
Expand Down Expand Up @@ -721,6 +729,7 @@ export class NWCClient {
"list_transactions",
request,
(response) => !!response.transactions,
{ replyTimeout: 10000 },
);

return result;
Expand Down Expand Up @@ -819,6 +828,7 @@ export class NWCClient {
nip47Method: Nip47SingleMethod,
params: unknown,
resultValidator: (result: T) => boolean,
timeoutValues?: Nip47TimeoutValues,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less important, but can this also be added to the executeMultiNip47Request method?

): Promise<T> {
await this._checkConnected();
await this._checkCompatibility();
Expand Down Expand Up @@ -867,7 +877,10 @@ export class NWCClient {
);
}

const replyTimeoutCheck = setTimeout(replyTimeout, 60000);
const replyTimeoutCheck = setTimeout(
replyTimeout,
timeoutValues?.replyTimeout || 60000,
);

sub.onevent = async (event) => {
// console.log(`Received reply event: `, event);
Expand Down Expand Up @@ -930,7 +943,10 @@ export class NWCClient {
),
);
}
const publishTimeoutCheck = setTimeout(publishTimeout, 5000);
const publishTimeoutCheck = setTimeout(
publishTimeout,
timeoutValues?.publishTimeout || 5000,
);

try {
await this.relay.publish(event);
Expand Down