Skip to content

Commit

Permalink
fix: queue on the node event loop to mitigate "waitAsync is already r…
Browse files Browse the repository at this point in the history
…unning bug" (#455)

fixes #452 
* fix for waitAsync is already running bug
* only reset bWaitStarted to false when whole queue is processed

---------

Co-authored-by: Philipp Thiele <philipp.thiele@sap.com>
  • Loading branch information
philippthiele and philith committed Apr 27, 2023
1 parent 46efbfc commit bed997e
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions client-side-js/injectUI5.js
Expand Up @@ -26,7 +26,9 @@ async function clientSide_injectUI5(config, waitForUI5Timeout, browserInstance)
},
objectMap: {
// GUID: {}
}
},
bWaitStarted: false,
asyncControlRetrievalQueue: []
}

/**
Expand Down Expand Up @@ -57,13 +59,27 @@ async function clientSide_injectUI5(config, waitForUI5Timeout, browserInstance)
oOptions = oOptions || {}
_autoWaiterAsync.extendConfig(oOptions)

_autoWaiterAsync.waitAsync(function (sError) {
if (sError) {
errorCallback(new Error(sError))
} else {
callback()
}
})
const startWaiting = function () {
window.wdi5.bWaitStarted = true;
_autoWaiterAsync.waitAsync(function (sError) {
const nextWaitAsync = window.wdi5.asyncControlRetrievalQueue.shift();
if (nextWaitAsync) {
setTimeout(nextWaitAsync); //use setTimeout to postpone execution to the next event cycle, so that bWaitStarted in the UI5 _autoWaiterAsync is also set to false first
} else {
window.wdi5.bWaitStarted = false;
}
if (sError) {
errorCallback(new Error(sError))
} else {
callback()
}
})
}
if (!window.wdi5.bWaitStarted) {
startWaiting();
} else {
window.wdi5.asyncControlRetrievalQueue.push(startWaiting);
}
}
window.wdi5.Log.info("[browser wdi5] window._autoWaiterAsync used in waitForUI5 function")
})
Expand Down

0 comments on commit bed997e

Please sign in to comment.