flushTransaction() lock

This commit is contained in:
Tim Olson
2023-11-11 00:34:51 -04:00
parent 344445587d
commit 580f0f0f9b
2 changed files with 17 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
export function applyFills( orderStatus, filled ) { export function applyFills( orderStatus, filled ) {
console.log('apply fills', orderStatus, filled) // console.log('apply fills', orderStatus, filled)
orderStatus[4] = filled[0][0] orderStatus[4] = filled[0][0]
orderStatus[5] = filled[0][1] orderStatus[5] = filled[0][1]
for( const i in filled[1] ) { for( const i in filled[1] ) {
@@ -7,5 +7,5 @@ export function applyFills( orderStatus, filled ) {
orderStatus[6][i] = filledIn orderStatus[6][i] = filledIn
orderStatus[7][i] = filledOut orderStatus[7][i] = filledOut
} }
console.log('applied fills', orderStatus) // console.log('applied fills', orderStatus)
} }

View File

@@ -199,12 +199,25 @@ export function pendTransaction(sender) {
} }
let flushing = 0 // semaphore
export function flushTransactions() { export function flushTransactions() {
// noinspection JSIgnoredPromiseFromCall flushing++
asyncFlushTransactions() if( flushing === 1 )
// noinspection JSIgnoredPromiseFromCall
asyncFlushTransactions()
} }
export async function 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() // todo rework into flushTransactions()
const s = useStore() const s = useStore()
if( s.provider === null ) { if( s.provider === null ) {