[ImageToolbox] async and await JS
imagetoolbox
Web icon
Forge component by João Quitério
Application Type
Reactive

(forgot the link to ImageToolbox forge component, idk why is there)

Hi,

I'm trying to wait for a Promise in order to simulate a sleep() without stop the main thread. But OutSystems don't recognize the JS. This can be executed in a broswer without problems and it works.

This is my code:


/*jshint esversion: 6*/

var audioPlay = document.getElementById("AudioPlayer").firstElementChild;

var audioDurationMs = audioPlay.duration * 1000;

function audioEnd() {

  return new Promise(resolve => {

    setTimeout(() => {

      resolve();

    }, audioDurationMs);

  });

}

async function check() {

  audioPlay.play();

  await audioEnd();

  console.log("test");

}

check();


As you can see, OutSystems tell me there are syntax errors...

Any idea to accomplish this in client-side?

Regards.

Champion
Solution

Hi Alvaro,

Have you tried using that JS code in a JS script instead of directly in a client action?

This way I don't get any errors or warnings:


Cheers

In spite of the warning "has syntax errors. Using it in your app might cause runtime errors." the behaviour it's correct.

Thank you.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.