I am learning some async foundations and callback functions in Javascript
And I want to return a random boolean after a random delay
I have a function that when invoked returns a callback
but I don't get how to just return the testValue
from the callback after the setTimeout
is resolved.
const returnTestValue = () => {
const delay = 7000 + Math.random() * 7000;
const testValue = Math.random() > 0.5;
return callback => {
window.setTimeout(() => callback(testValue), delay);
};
};
The returned callback after calling returnTestValue()
callback => {
window.setTimeout(() => callback(testValue), delay);
}