1

console.log("==PARALLEL with await Promise.all==");
        parallel();
    // Definition of parallel function to Start 5 "jobs" in parallel and wait for both of them to complete 
        async function parallel() {
        await Promise.all([
        (async () => await a()),
        (async () => await b()),
        (async () => await c()),
        (async () => await d()),
        (async () => await e()),
        ]);
        }
        function a()
        {
        console.log("In function a ");
        return Promise.resolve(1);
        }
        function b(){
        console.log("In function b ");
        return Promise.resolve(2);
        }
        function c(){
        console.log("In function c ");
        return Promise.resolve(3);
        }
        function d(){
        console.log("In function d ");
        return Promise.resolve(4);
        }
        function e(){
        console.log("In function e ");
        return Promise.resolve(5);
        }

refer to my original question in IFFE

I am little being confused...my question is why was Javascript ignoring my functions a,b,c,d,e (observed in debugger) and only when I used the IFFE concept did it run properly?

Michael36
  • 150
  • 11
  • 1
    JavaScript does not force you to use them, it simply sometimes makes sense to have them and sometimes it does not. You simply need to understand what it actually does to understand when and why you want / do not want to use them. – luk2302 Oct 08 '22 at 10:47
  • 2
    _"refer to my original question in..."_ - This is not how SO works. A question has to contain everything necessary to reproduce/understand the actual problem. Only a link to another question, even on SO, is not enough -> [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Andreas Oct 08 '22 at 10:48
  • true but if u see the JS Code snippet in my original question it was hellbent on me to use IFFE Concept else it was bypassing the functions.. – Michael36 Oct 08 '22 at 10:50
  • An array of functions is not the same as an array of values (`Promise`s). – Andreas Oct 08 '22 at 10:51
  • @andreas ok i will attach the JS code snippet in few minutes – Michael36 Oct 08 '22 at 10:51
  • 1
    If I just write a JS function nothing happens because nothing calls that function. If I write an IFFE I do actually call a / that function. As already said: You simply need to understand IFFEs. – luk2302 Oct 08 '22 at 10:53
  • Andreas refer to your latest comment i tried out an array of function -await Promise.all([a(), b(), c(), d(), e()]) ,and it worked.credit @emiel-zuurbier – Michael36 Oct 08 '22 at 11:06

0 Answers0