Skip to content

Commit

Permalink
fix for waitAsync is already running bug
Browse files Browse the repository at this point in the history
  • Loading branch information
philith committed Apr 25, 2023
1 parent 46efbfc commit 443b702
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions client-side-js/injectUI5.js
Original file line number Diff line number Diff line change
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,26 @@ 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) {
window.wdi5.bWaitStarted = false;
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
}
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 443b702

Please # to comment.