Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Asynchronous functions question

    Dear All,

    I'm new to this forum. I'm a JavaScript beginner and I've got a question in my project that is breaking my head.

    On the following code, functions funcAsync1, 2, 3 and 4 call asynchronous functions.


    Code:
    function allSteps()
    	{
    		step = 0;
    		Sequencer(0,9999);
    		
    		function Sequencer(step, result) {
    		step++;
    		switch (step) {
    			case 1: step1(step); break;
    			case 2: step2(step); break;
    			case 3: step3(step); break;
    			case 4: step4(step); break;
    			default: return;
    		}
    
    		function step1(stepN){funcAsync1();}
    		
    		function step2(stepN){funcAsync2();}
    		
    		function step3(stepN){funcAsync3();}
    		
    		function step4(stepN){funcAsync4();}
    		
    	}
    So the idea is when step1 returns, all its asynchronous work has finished, when step2 returns, all its asynchronous work has finished and so on.

    How can I accomplish that?

    Kind Regards

  2. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,650
    Thanks
    24
    Thanked 580 Times in 573 Posts
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •