Alpha Video Training
Results 1 to 23 of 23

Thread: To Wait (Synchronous) for a function to complete - then proceed

  1. #1
    Member
    Real Name
    MobApp
    Join Date
    Sep 2013
    Posts
    312

    Default To Wait (Synchronous) for a function to complete - then proceed

    I know to use timer or delay requirement using setTimeout function, but my requirement is different - I need to wait for a process or function to complete before proceeding.

    To make an Asynchronous (no wait to complete to continue) function act like an Synchronous (Wait to complete to continue), so the rest of the code waits until this is completed. Some type of pause function without hardcoding how many milliseconds to pause.

    The following will not work.
    setTimeout ( function(){
    {
    ...more_code...
    dialog.object}.panelSetActive('PANELCARD_3');
    },200);
    Thanks!

  2. #2
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    The easiest thing to do would be to return the code to execute from the ajaxCallback (I assume this is happening after a callback?)

    Alternatively, you could use a global variable, like {dialog.object}.__continue = false. Set __continue = true when the code you're waiting to finish is done. Then you can use something like setInterval to check the variable & then execute the desired code - note: you will want to clear your setInterval after executing whatever it is that you wanted to do next, otherwise it will keep executing in a loop.

    What process are you running that requires waiting? Is there a server-side or client-side event you could hook?
    Alpha Anywhere latest pre-release

  3. #3
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    you could also just nest your setTimeout:

    Code:
    // example from mdn page on setInterval:
    (function loop(){
       setTimeout(function(){
    
          // logic here
    
          // recurse
          loop();
    
      }, 1000);
    })();
    Alpha Anywhere latest pre-release

  4. #4
    Member
    Real Name
    MobApp
    Join Date
    Sep 2013
    Posts
    312

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Sarah, Awesome Ideas! I am already coding. Thanks!

  5. #5
    Member
    Real Name
    MobApp
    Join Date
    Sep 2013
    Posts
    312

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    and this is happening after a callback... Thanks!

  6. #6
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Quote Originally Posted by JPMPA View Post
    and this is happening after a callback... Thanks!
    If you're code needs to execute after the callback is complete, I would see if you could just return the javascript from the callback instead of using setTimeout/setInterval/etc. It'll be guaranteed to happen after the callback completes and you don't have to spend your brain power guessing how many milliseconds of waiting are needed to finish the operation.
    Alpha Anywhere latest pre-release

  7. #7
    Member
    Real Name
    Phil Major
    Join Date
    Feb 2006
    Posts
    13

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Hi,

    Can you not just click the synchronous checkbox in an action JavaScript window? See attached picture ... Note I have clicked the 'Explain this' hyperlink. Call the callbacks using ActionJavascript and click the checkbox. Should work!

    synchronousJS.jpg

    Phil

    HTH

  8. #8
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,216

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    I use this NEW feature and I love it. I put up a waiting message first, run the process, then hide the wait message. It works great! Thank you Alpha. It's the little things like this that make using Alpha a joy to work in.

  9. #9
    Member
    Real Name
    MobApp
    Join Date
    Sep 2013
    Posts
    312

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Great feedback. Synchronous checkbox is excellent.

  10. #10
    Member nlights's Avatar
    Real Name
    pertti karjalainen
    Join Date
    May 2011
    Location
    California
    Posts
    217

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Just a thought: You could always chain JS functions.

    So rather than doing something like this (which doesn't work)...

    Code:
    retval = longProcess();
    alert(retval);
    ...do something like this (not tested, but the gist of it is there)

    Code:
    function a(){
       retval = longProcess();
       return b(retval);
    }
    
    function b(passedVal) {
       alert(passedval);
    }
    Now alert() would wait until longProcess() finishes.

  11. #11
    Member
    Real Name
    MobApp
    Join Date
    Sep 2013
    Posts
    312

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Thanks!

  12. #12
    Member
    Real Name
    Pevisha Joshi
    Join Date
    Jul 2014
    Location
    Vancouver, Canada
    Posts
    53

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Hi Guys,

    I have a similar problem but the solutions here do not seem to work for it.

    I have a slider and whenever the slider changes the value, it calls a function. The function has some long calculation going on so, it is a little slow. So, when you are moving the slider, it hangs.
    I am trying to set up a timer so, that if the slider moves before 2 seconds, the function is not called. But if the slider is not moving for 2 or more seconds, the function gets called.

    I tried using setInterval function but it kept calling the function after 2 seconds of each slider move so, at one point it hangs.

    I was wondering if there is a way to work around it. Or, if I can reset the timer every time the slider moves?

    Thanks,

    Pevisha

  13. #13
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Quote Originally Posted by PevishaJ View Post
    Hi Guys,

    I have a similar problem but the solutions here do not seem to work for it.

    I have a slider and whenever the slider changes the value, it calls a function. The function has some long calculation going on so, it is a little slow. So, when you are moving the slider, it hangs.
    I am trying to set up a timer so, that if the slider moves before 2 seconds, the function is not called. But if the slider is not moving for 2 or more seconds, the function gets called.

    I tried using setInterval function but it kept calling the function after 2 seconds of each slider move so, at one point it hangs.

    I was wondering if there is a way to work around it. Or, if I can reset the timer every time the slider moves?

    Thanks,

    Pevisha
    setInterval executes every x milliseconds. setTimeout executes once. It would probably be easier to use setTimeout:

    Code:
    //JavaScript Code Section
    {grid.object}.timer = null;
    
    //call function from onslide event:
    var handleSlider = function (e,id) {
      clearTimeout({grid.object}.timer);
      {grid.object}.timer = setTimeout(function (e,id) {
        alert('done');
      }, 2000);
    };
    Alpha Anywhere latest pre-release

  14. #14
    Member
    Real Name
    Pevisha Joshi
    Join Date
    Jul 2014
    Location
    Vancouver, Canada
    Posts
    53

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Thanks!

    I will try that out.

    Pevisha

  15. #15
    Member
    Real Name
    Anita Headley
    Join Date
    Jul 2013
    Location
    Olympia, WA
    Posts
    183

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    I have a somewhat similar problem, but with xbasic code. I am using the File upload function to get data file from the user. I then use the 'After upload' to call an xbasic function to put the data in a holding table. the return from this first xbasic function is a message to the user that the data has been loaded. I then need to use another xbasic to call the validation processes (SQLServer stored procedure) that checks the data and moves it to another table. The second xbasic function returns a message that the processing is complete. THE PROBLEM: I can't figure out how to run the second xbasic function. When I call it from the first xbasic function OR make an xbasic function that calls both sequentially, the user never gets the intermediate 'Data Loaded, Please wait while processing' message. Any ideas? Should I post this to a separate thread?

  16. #16
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Quote Originally Posted by Anita Headley View Post
    I have a somewhat similar problem, but with xbasic code. I am using the File upload function to get data file from the user. I then use the 'After upload' to call an xbasic function to put the data in a holding table. the return from this first xbasic function is a message to the user that the data has been loaded. I then need to use another xbasic to call the validation processes (SQLServer stored procedure) that checks the data and moves it to another table. The second xbasic function returns a message that the processing is complete. THE PROBLEM: I can't figure out how to run the second xbasic function. When I call it from the first xbasic function OR make an xbasic function that calls both sequentially, the user never gets the intermediate 'Data Loaded, Please wait while processing' message. Any ideas? Should I post this to a separate thread?
    Include the call to the next xbasic function in the same code that displays the wait message.
    Alpha Anywhere latest pre-release

  17. #17
    Member
    Real Name
    Anita Headley
    Join Date
    Jul 2013
    Location
    Olympia, WA
    Posts
    183

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    ??
    I can make an Action JavaScript Messagebox happen after the call to the first xbasic function (which is called from the fileupload Action) or I can put the message in the return JavaScript from the first xbasic function. I can not find an Action JavaScript that just calls an xbasic function and if I call the second xbasic function from the first xbasic function, the message does not get displayed until after the second xbasic function has finished. I don't know how to call an xbasic function with JavaScript.

  18. #18
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,334

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Quote Originally Posted by Anita Headley View Post
    ??
    I can make an Action JavaScript Messagebox happen after the call to the first xbasic function (which is called from the fileupload Action) or I can put the message in the return JavaScript from the first xbasic function. I can not find an Action JavaScript that just calls an xbasic function and if I call the second xbasic function from the first xbasic function, the message does not get displayed until after the second xbasic function has finished. I don't know how to call an xbasic function with JavaScript.
    Use the Ajax Callback Action Javascript action to make an ajax callback to the server to execute Xbasic. You can create this as a javascript action and call it in the on close event for the message box, which is available when the Message box action is configured to use an advanced message box.
    Alpha Anywhere latest pre-release

  19. #19
    Member
    Real Name
    Anita Headley
    Join Date
    Jul 2013
    Location
    Olympia, WA
    Posts
    183

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    What I've got is so convoluted and it still doesn't work - the message is showing up before the file is even selected. This should be simple:
    Please help.
    What I need:
    1) Button for user to click to start process
    2) File upload ( I am using File Upload - User Defined Action called from the button)
    3) xbasic function to move the data into the 'upload' table (This xbasic is being called from the File Upload and works fine)
    4) message to screen to let user know that file has been uploaded
    5) another xbasic function that calls a SQLServer stored procedure that does the validation processing and puts the data in the Data tables.

    It works if I leave out step 4 and call the second xbasic function from the first xbasic function, but the users WANT that intermediate message.

  20. #20
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,619

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    A suggestion:

    Let step 3 finish by opening a container window with the message, and an "OK" button or whatever you need. Open the window with this:

    Code:
    {dialog.object}.showContainerWindow(this,'WINDOW_UPLOADCONFIRM');
    Then, the click of that "OK" button closes the container window, and calls step 5.

    Code:
    {dialog.object}.hideContainerWindow('WINDOW_UPLOADCONFIRM');
    {dialog.object}.ajaxCallback('', '', 'SQLCall', '');
    -Steve


  21. #21
    Member
    Real Name
    Anita Headley
    Join Date
    Jul 2013
    Location
    Olympia, WA
    Posts
    183

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    got it working, thank you

  22. #22
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,619

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Good - did you use the method I suggested or some other approach? Posterity wants to know.
    -Steve


  23. #23
    Member
    Real Name
    Anita Headley
    Join Date
    Jul 2013
    Location
    Olympia, WA
    Posts
    183

    Default Re: To Wait (Synchronous) for a function to complete - then proceed

    Did popup messagebox after first xbasic procedure and ajaxcallback action script called from button of popup messagebox.

Similar Threads

  1. How should I proceed?
    By BudSch in forum QReportBuilder
    Replies: 2
    Last Post: 03-01-2012, 05:25 PM
  2. How do I proceed?
    By BudSch in forum QReportBuilder
    Replies: 3
    Last Post: 02-20-2012, 06:31 PM
  3. wait for xdailog to complete
    By crimmelcp in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 12-06-2010, 04:07 PM
  4. How to proceed?
    By katz3 in forum Database Design
    Replies: 1
    Last Post: 06-14-2009, 01:19 PM
  5. Please Wait Function Implementation
    By jkletrovets in forum Alpha Five Version 8
    Replies: 2
    Last Post: 06-04-2007, 11:07 PM

Bookmarks

Posting Permissions

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