setTimeout.js

let getDataOne = (cb) => { setTimeout(function(){ //calling the callback cb('dummy data one') }, 1000); } let getDataTwo = (cb) => { setTimeout(function(){ //calling the callback cb('dummy data two') }, 1000); } //Both these functions mimic the async code with setTimeout. //Once the desired time has elapsed, setTimeout will call the //passed callback cb with value dummy data one and dummy data two, //respectively. Let’s see how we will be calling these two functions //without generators in the first place: getDataOne((data) => console.log("data received",data)) getDataTwo((data) => console.log("data received",data)) //That code will print the following after 1,000 ms: //Result Running data received dummy data one data received dummy data two
Simple Asynchronous Functions

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.