Use tokio async/await instead of callbacks

This commit is contained in:
junderw
2023-06-24 19:28:19 -07:00
committed by Mononaut
parent 5f161e73c7
commit 8cfda1a546
6 changed files with 148 additions and 67 deletions

View File

@@ -342,12 +342,7 @@ class MempoolBlocks {
// run the block construction algorithm in a separate thread, and wait for a result
try {
const { blocks, rates, clusters } = this.convertNapiResultTxids(
await new Promise((resolve) => {
napiAddon.make(
new Uint8Array(mempoolBuffer),
resolve,
);
})
await napiAddon.make(new Uint8Array(mempoolBuffer)),
);
this.rustInitialized = true;
const processed = this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
@@ -381,13 +376,10 @@ class MempoolBlocks {
// run the block construction algorithm in a separate thread, and wait for a result
try {
const { blocks, rates, clusters } = this.convertNapiResultTxids(
await new Promise((resolve) => {
napiAddon.update(
await napiAddon.update(
new Uint8Array(addedBuffer),
new Uint8Array(removedBuffer),
resolve,
);
})
),
);
this.processBlockTemplates(newMempool, blocks, rates, clusters, saveResults);
logger.debug(`RUST updateBlockTemplates completed in ${(Date.now() - start)/1000} seconds`);