Home Is javascript asynchronous function internally designed using settimeout, setintervals etc?
Reply: 1

Is javascript asynchronous function internally designed using settimeout, setintervals etc?

jwkoo
1#
jwkoo Published in 2018-01-11 04:04:43Z

Is javascript asynchronous function internally designed using settimeout function?

since javscript language is based on single threaded, it depends on the event-loop which is supported by the browser or task queue or something to create asynchronous function.

so is settimeout function only the way to make asynchronous function in javascript?

Mosè Raguzzini
2#
Mosè Raguzzini Reply to 2018-01-11 11:08:31Z

If you want to take advantage of separate processes you can use Web Workers (https://developer.mozilla.org/en-US/docs/Web/API/Worker) if they are supported by your target browsers.

I.E:

var myWorker = new Worker('worker.js');
var first = document.querySelector('#number1');
var second = document.querySelector('#number2');

first.onchange = function() {
  myWorker.postMessage([first.value,second.value]);
  console.log('Message posted to worker');
}

Another possibility is to use function* like redux-saga does.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.326783 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO