Posting a simplified version of the original question:
I am trying to write a JXA script to simultaneously do the following
Launch another function / script that at the same time as the HTML prompt is visible.
I learnt that JXA does not have setInterval and clearInterval and so could not figure out how to do asynchronous function launch.
For now, plan is to use multiple KM macros and enable / disable macro to run 1 and 2 simultaneously (Thank you @DanThomas).
At some point will try to figure how to do it in JXA - at first glance it appears run-jxa package can help.