Is it possible to write a custom asynchronous function without the use of JS's timer functions such as setTimeout
and setInterval
?
I have two code examples below, one that succeeds(goodboy.js) and one that fails(goodboyfail.js). I originally thought, goodboy.js would fail because I assumed
- Simply defining
get
with a callback function would make it asyncronous praise
would be undefined when it was executed.
However, the console.log
messages seem to indicate that the get
function executes syncronously.
I got the expected behviour in goodboyfail.js by adding a delay.
- I've ignored error handling
- I am aware that the 0ms applied to the setTimeout(goodboyfail.js) is not actually a 0 second delay but will be the browser minimum ~4ms.