Make server side code wait

Hi Community,

Hopefully an easy question -

I am calling a server side method from a client method and I need the server side method to wait a few seconds to allow the items to save before processing. I tried the standard sleep commands but they don't seem to work. I also tried to use a timeout on the client side but since I am closing the window after the save, it sometimes will not allow the code to continue.

Any suggestions?

Parents
  • Hi Morgan

    do you really need your server Method to wait? Or shall your client Method wait until the Server Method is finished?

    Typical scenario: You have a dialog with button. The onClick button event calls a server Method. When client Method is finished, you want to close the dialog and throw an success or failed notification based on the server Method result.

    If you have a long running server task, it can happen that the client Method tries to analyze the result of the server Method, while the server Method isn´t finished yet. In this case it can happen that dialog closes and you get wrong notification. This is normal JS behavior. It never waits.

    If this is your scenario, you have to call the server Method inside a promise or use async/await. This way you force the client code to wait. 

    Angela

Reply
  • Hi Morgan

    do you really need your server Method to wait? Or shall your client Method wait until the Server Method is finished?

    Typical scenario: You have a dialog with button. The onClick button event calls a server Method. When client Method is finished, you want to close the dialog and throw an success or failed notification based on the server Method result.

    If you have a long running server task, it can happen that the client Method tries to analyze the result of the server Method, while the server Method isn´t finished yet. In this case it can happen that dialog closes and you get wrong notification. This is normal JS behavior. It never waits.

    If this is your scenario, you have to call the server Method inside a promise or use async/await. This way you force the client code to wait. 

    Angela

Children