šŸ“™ Understanding Neuronal Networks presale is now open - 20% off discount!

What is an executor function for a Javascript promise?

We can pass an executor function to the constructor of a Javascript native promise. It takes two parameters: the resolve and rejects callouts of that promise:

new Promise( 
    () => {...} 
).then ( ... );

Based on our needs we can customize the behavior of that Promise using the exector.

For example, we can have for this executor function to automatically trigger the resolve or the rejects if our promise does not get an answer after some amount of time.

const executor = (resolve, reject) => {
    setTimeout(
        () => reject("Did not get an anwser after 1 sec")
    , 1000);
};

// this promise will automatically be rejected after 1 sec
new Promise(executor).then(result => {
    console.log(result);
});

More details about it here.

šŸ“– Neural Networks from Scratch - Presale

I'm writing a book about the timeless foundational concepts of neural networks for JavaScript developers. Go from if-else to weights and biases by building tiny AI models from scratch!

šŸ“– Neural Networks from Scratch - Presale

I'm writing a book about the timeless foundational concepts of neural networks for JavaScript developers. Go from if-else to weights and biases by building tiny AI models from scratch!


Leave a Reply

Your email address will not be published. Required fields are marked *