Skip to content

Commit

Permalink
attach listener first, then do a "static" check for condition
Browse files Browse the repository at this point in the history
  • Loading branch information
geoknee committed Oct 12, 2023
1 parent c92dc4b commit a6e1ac0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/nitro-rpc-client/src/rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export class NitroRpcClient implements RpcClientApi {
channelId: string,
status: ChannelStatus
): Promise<void> {
const ledger = await this.GetLedgerChannel(channelId);
return new Promise((resolve) => {
if (ledger.Status == status) resolve();
const promise = new Promise<void>((resolve) => {
this.transport.Notifications.on(
"ledger_channel_updated",
(payload: LedgerChannelUpdatedNotification["params"]["payload"]) => {
Expand All @@ -77,14 +75,16 @@ export class NitroRpcClient implements RpcClientApi {
}
);
});
const ledger = await this.GetLedgerChannel(channelId);
if (ledger.Status == status) return;
return promise;
}

public async WaitForPaymentChannelToHaveStatus(
channelId: string,
status: ChannelStatus
): Promise<void> {
const channel = await this.GetPaymentChannel(channelId);
return new Promise((resolve) => {
const promise = new Promise<void>((resolve) => {
if (channel.Status == status) resolve();
this.transport.Notifications.on(
"payment_channel_updated",
Expand All @@ -97,6 +97,10 @@ export class NitroRpcClient implements RpcClientApi {
}
);
});

const channel = await this.GetPaymentChannel(channelId);
if (channel.Status == status) return;
return promise;
}

public onPaymentChannelUpdated(
Expand Down

0 comments on commit a6e1ac0

Please sign in to comment.