diff --git a/order.js b/order.js index d40d6a8..6711ee9 100644 --- a/order.js +++ b/order.js @@ -13,17 +13,18 @@ export function sendVaultOrders( socket, chainId, vault ) { console.log('vault closed orders', closedIndexes) const statuses = {} const indexes = [...JSON.parse(openIndexes), ...JSON.parse(closedIndexes)] + const proms = [] if( openIndexes !== null ) { for (const orderIndex of indexes) { // there is a race condition here since we need multiple queries to get the complete order status, // so we check for nulls and exclude such an order, since it was deleted and no longer active. - const status = await orderStatus(chainId, vault, orderIndex) - if (status !== null) - statuses[orderIndex] = status + proms.push(orderStatus(chainId, vault, orderIndex).then((status)=>{ + if (status !== null) + statuses[orderIndex] = status + })) } } console.log('vault archived orders', recents) - const proms = [] for( let [orderIndex, status] of recents ) { if( !(orderIndex in statuses) ) { // only write the database version if there's no open order in the memcache @@ -47,7 +48,10 @@ export function unsubVaultOrders( socket, chainId, vault ) { export async function orderStatus( chainId, vault, orderIndex ) { const orderKey = `${vault}|${orderIndex}` let status = await orderStatuses.get(chainId, orderKey) - if( status !== null ) { + if( status === null ) { + console.warn(`Could not find order status for ${chainId}|${vault}|${orderIndex}`) + } + else { status = JSON.parse(status) await fillOrderStatus(chainId, orderKey, status) }