I’m trying to show progress of the process when the button is clicked
But the problem is that the html is updated after all process has finished
even though I put the code right at the top
Panel HTML changes do NOT have to be included inside the executeAsModal code. You could call the HTML changes and then invoke the execuateAsModal function afterwards. HTML panel changes do not need to be asychronous so they don’t need to “await” anything.
I would advise that you go and study how asynchronous JavaScript works as that’s where your problem lies (and not with anything UXP related).
It can be a tricky thing to get your head around at first, but you are going to keep hitting up against it.
In a nutshell - using the await keyword will cause code execution to wait until the awaited code is completed.
Here’s a rough pseudocode example for you:
async function exampleFunc () {
// no await
console.log("foo");
// await function that takes time to complete
await anotherExampleFunc() {
// Do stuff that takes time - e.g. API call
console.log("donk")
}
// no await
console.log("bar")
}
The output will be:
foo
donk
bar
because the final log has to wait for anotherExampleFunc to complete.
Without async/await the output would be:
foo
bar
donk
because the JavaScript engine will start executing the anotherExampleFunc and move straight on to the final log before it completes.
It also appears that you are asking two questions in this thread - your original HTML update one, and then a batchPlay/executeAsModal question. You’d be better served creating a new thread so as not to confuse the issue.
executeAsModal() calls the showLayerNames function in your code, but I don’t see where you’ve defined that function. I just see “rasterizeLayers()” and “selectAll()” functions. Are these two within the showLayerNames function?
Also, both “rasterizeLayers()” and “selectAll()” functions contain