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 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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 },
rolznz marked this conversation as resolved.
Show resolved Hide resolved
);
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?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Dayvvo what do you think about this one?

Copy link
Author

Choose a reason for hiding this comment

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

@rolznz sounds good. Made a commit for that !!

): 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