From 580f0f0f9bfd9bc488bdf30af1acb03c1c211a2b Mon Sep 17 00:00:00 2001 From: Tim Olson <> Date: Sat, 11 Nov 2023 00:34:51 -0400 Subject: [PATCH] flushTransaction() lock --- src/blockchain/common.js | 4 ++-- src/blockchain/wallet.js | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/blockchain/common.js b/src/blockchain/common.js index 87bc8c2..3d86e1e 100644 --- a/src/blockchain/common.js +++ b/src/blockchain/common.js @@ -1,5 +1,5 @@ export function applyFills( orderStatus, filled ) { - console.log('apply fills', orderStatus, filled) + // console.log('apply fills', orderStatus, filled) orderStatus[4] = filled[0][0] orderStatus[5] = filled[0][1] for( const i in filled[1] ) { @@ -7,5 +7,5 @@ export function applyFills( orderStatus, filled ) { orderStatus[6][i] = filledIn orderStatus[7][i] = filledOut } - console.log('applied fills', orderStatus) + // console.log('applied fills', orderStatus) } diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 706dca1..e2a6a2c 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -199,12 +199,25 @@ export function pendTransaction(sender) { } +let flushing = 0 // semaphore + export function flushTransactions() { - // noinspection JSIgnoredPromiseFromCall - asyncFlushTransactions() + flushing++ + if( flushing === 1 ) + // noinspection JSIgnoredPromiseFromCall + asyncFlushTransactions() } export async function asyncFlushTransactions() { + let counter + do { + counter = flushing + await asyncFlushTransactions2() + } while( flushing > counter) + flushing = 0 +} + +export async function asyncFlushTransactions2() { // todo rework into flushTransactions() const s = useStore() if( s.provider === null ) {