0

Just want to understand the usage of busy indicator does it alternate to timeout/putting wait etc.

for example have following line of code in mainfunct()

1. busy.show();
2. callcustom(); --asynch function without callback this is calling xmlhttpRequest etc.
3. busy.hide();
4. callanothercustom(); -- asynch function without callback

now question is

  1. does line 4 will be executed only when busy.hide() completes and line 3 only when line 2 is completed while without busy all (2,4) will be called inside mainfunct() without waiting line 2 to complete...

  2. when busy.hide() is being called is there any timer setup which holds until line 2 finishes and then hide and call line 4.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
MichealSmith
  • 183
  • 1
  • 2
  • 9

2 Answers2

0

A busyIndicator's show and hide functions only control when to display the indicator and when to hide the indicator. They have no effect what-so-ever on anything else going on in your code.

In other words your code is basically:

  1. callcustom()
  2. callanothercustom()

In your customcode you can still make sure that callanothercustom will be called only when it's finished by adding your own callback... I assume this is AJAX inside of it, so: jQuery ajax success callback function definition

function callcustom() {
    $.ajax({
        url : 'example.com',
        type: 'GET',
        success : callanothercustom
    })
}

And then in callanothercustom you can busy.hide...
Or any other combination of business logic - it really depends on what's going on in your code.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • So it means BusyIndicator just to show/hide indicator, now to handle the asynchronous func call i have to add timer ? or is there any WL API i can use, I am mostly getting this issue with xmlhttprequest used to submit page in windows enviornment. – MichealSmith Jun 06 '15 at 11:59
0

In my opinion, the only main use case for using a busy indicator is a Long running synchronous task that's blocking UI. Let's say greater than 2 seconds long. Hopefully, these are few are far between.

If you have asynch tasks, then the UI is not blocked and user can interact. If you are relying on the results for next steps as you imply above, then you must have a callback/promise to trigger the next steps. If you want the user to be blocked until the async task is complete, then treat it as a synch task and show the Busy.

Be aware, use of Busy Indicator is now seen mostly as an anti-pattern. Its basically yelling at your user "See how slow this app is!". Sometimes you cannot avoid dead time in your app, such as fetching a large block of data to generate a view, but there are many ways to mitigate this. An example may be to -- get something on the view as fast as possible (< 1 sec), and then backfill with larger data. Just always ask yourself WHY you need this Busy, and can I work out a way to avoid it, but not leave the user wondering what the app is doing.

Karl Bishop
  • 251
  • 1
  • 5