How to set timeout for Script web.download()? Do we have setTimeout/clearTimeout

If the website down or internet connection down, the script keep trying to download for long time and SambaPOS will not respond during the script running.

I know there is script to check internet connection but what if internet OK but website down (which happen to me today).

How can I set timeout for web.download() for like 10 sec?

EDIT: I would prefer not to run internet connectivity check every time executing script. This would slow down the process.

I have tested my json post with incorect url to simulate website down and didnt lock up samba… seemed to pause for bit longer but not too much.
PS, the internet script could just be changed to ping the website/server rather than google DNS.
Google DNS was chosen as an internet chack as up time would be pretty close to 100% so good test for internet connectivity.

How are you triggering the script?

Automation Command Button.

I’m not sure lock up for how long maybe my staff just impatient and keep clicking it then windows ask to close SambaPOS. I think.

you might need to code an alternative result if it doesn’t immediately return.

Yes, that is what I’m looking for. How to get alternative return if it not return data in line 5 sec.

Do we have setTimeout()/clearTimeout() function?

I tried:

function test() {
	var timer;
	timer = setTimeout(TimeOutTest, 5000);
	sleep(1000);
	clearTimeout(timer);
	return "OK";
}

function TimeOutTest() {
  return "This Take Too Long";	
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

Result: Object Expected

Expect: sleep(1000) should return “OK”. sleep(6000) should return “This Take Too Long”.