Jump to content
jca

Asynchronous Events Interuppting Main Thread

Recommended Posts

This isn’t really a bug more of a question about how this could happen. 

For example - I have a script, at the start of the loop there’s a function that checks if the account is logged in. 

I have a login handler event that I execute in my onStart, in the constructor I setAsync(). In the  execute() method I return 5000; if the account is logged in, if not I log the account in without pausing the script executor (as the loop is checking the opposite condition).

9/10 this login handler runs without interupping the main thread. Occasionaly it runs, the account logs in but the onLoop running on the main thread stops. 

No errors in the log, nothing. Anyone ever experienced this before?

Edited by jca
Link to comment
Share on other sites

Just to clarify:

  • You've built your own login event handler that is ran onStart
  • This event is set to asynchronous with a timeout of 5000ms
  • If you fail to login, the script should stop
  • If you successfully login, the script should proceed to the onLoop
  • The onLoop firstly checks to make sure you're logged in

 

If I've got this correct, then I don't think this is the right approach, because the onLoop will be called once onStart has been executed. You could block the onStart to delay the loop, but I would advise against it because onStart is only called once, and if there's a problem in its execution, the entire script would have to be restarted. Instead, I would handle all this within the loop; you can use a combination of boolean checks and timestamps to see where you are and where you should be:
 

onLoop

IF logged in

   DO stuff

ELSE IF we have entered in our login details

   IF we have clicked the login button

      IF 5 seconds have passed

         DO stop script

  ELSE

      DO click login

ELSE

   enter in login information

  • Like 1
Link to comment
Share on other sites

1 hour ago, liverare said:

Just to clarify:

  • You've built your own login event handler that is ran onStart
  • This event is set to asynchronous with a timeout of 5000ms
  • If you fail to login, the script should stop
  • If you successfully login, the script should proceed to the onLoop
  • The onLoop firstly checks to make sure you're logged in

 

If I've got this correct, then I don't think this is the right approach, because the onLoop will be called once onStart has been executed. You could block the onStart to delay the loop, but I would advise against it because onStart is only called once, and if there's a problem in its execution, the entire script would have to be restarted. Instead, I would handle all this within the loop; you can use a combination of boolean checks and timestamps to see where you are and where you should be:
 

onLoop

IF logged in

   DO stuff

ELSE IF we have entered in our login details

   IF we have clicked the login button

      IF 5 seconds have passed

         DO stop script

  ELSE

      DO click login

ELSE

   enter in login information

Thanks for the reply... yeah the event is non blocking. The tricky part is I swap login details so the login event also listens to that. 

I actually switched to your approach to test it and it is flawless now. Good to have confirmation of my thinking though! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...