Skip to content

Commit

Permalink
Merge pull request bitpay#1953 from micahriggan/feature/wait-fn
Browse files Browse the repository at this point in the history
adding wait function
  • Loading branch information
micahriggan authored Jan 28, 2019
2 parents d256e5c + a8dc68c commit 26b67dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/bitcore-node/src/services/p2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StateStorage } from '../models/state';
import { SpentHeightIndicators } from '../types/Coin';
import os from 'os';
import { Config, ConfigService } from './config';
import { wait } from "../utils/wait";
const Chain = require('../chain');

export class P2pManager {
Expand Down Expand Up @@ -230,7 +231,7 @@ export class P2pWorker {
});
while (!received) {
this.pool.sendMessage(this.messages.GetHeaders({ starts: candidateHashes }));
await new Promise(resolve => setTimeout(resolve, 1000));
await wait(1000);
}
});
}
Expand All @@ -246,7 +247,7 @@ export class P2pWorker {
});
while (!received) {
this.pool.sendMessage(this.messages.GetData.forBlock(hash));
await new Promise(resolve => setTimeout(resolve, 1000));
await wait(1000);
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/bitcore-node/src/utils/wait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function wait(time: number) {
return new Promise(resolve => setTimeout(resolve, time));
}

0 comments on commit 26b67dd

Please # to comment.