Link to home
Start Free TrialLog in
Avatar of Yair Abraham
Yair Abraham

asked on

how i use a async function

Hello this is my cod  for a test page

<script language="javascript" type="text/javascript">

	$(document).ready(function() {
		inLoop()
		
		/*var suport_fileReader;
		try { suport_fileReader = (window.FileReader) ? true : false }
		catch(e) {}
		document.getElementById("windowFileReader").innerHTML = suport_fileReader;
		document.getElementById("modernizrDragnDrop").innerHTML = Modernizr.draganddrop; */
		secFunc()
	});
	
	
	async function inLoop() {
	 var startTime = Date.now();
	 while ((Date.now() - startTime) < 3000) {
	  console.log("In Loop ", (Date.now() - startTime) )
	 }
	 alert(1)
	}
	
	function secFunc(){
	
	alert(2)
	}
</script>
<body>
<h1>Tests</h1>

Open in new window



1) I am expected that alert 2 will come before the alert 1 because the async  -
2) on IE11 async function inLoop() get error

I have long script that give a not responding for some time  i thought to use async   that the problematic function will run on the background - this is possible?
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

You don't want to wait for the inLoop response and go to the secFunc immediately, that it?

Do you want really to loop? if not what not just using `setTimeout()`?
Please take a look at
https://caniuse.com/#search=async

Specifically the async functions section.

Async for functions is not supported on IE11
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.