iOS Question Wait For behaviour

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

I discovered a strange thing. The app executes two subroutines in parallel. Each subroutine executes the same Wait For (myClass) myEvent. But last Wait For works only. Why ?

I can imagine a workaround (for example, to use different event names), but this is not very comfortable.
 

Attachments

  • WaitFor.zip
    1.6 KB · Views: 166
  • WaitForWorkaround.zip
    1.6 KB · Views: 177
Last edited:

j_o_h_n

Active Member
Licensed User
Is it because you are using the same object instance as the sender filter on each call?
If commonInstance was declared inslde Test1 it would be a different object instance each time.
However, here it is declared (only once) outside Test1 and so Wait For gets the same signature each time
and that means the second overwrites the first?
B4X:
Sub Test1 (Id As Int)

    commonInstance.RefreshTokens (Id)
    Wait For (commonInstance) RefreshTokensDone
    Log ("Wait For " & Id)
  
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is it because you are using the same object instance as the sender filter on each call?
If commonInstance was declared inslde Test1 it would be a different object instance each time.
That's the correct answer.

The sender filter feature is explained in the resumable subs video tutorial: https://www.b4x.com/etp.html

I'm also not sure why you need this loop. You can probably make it simpler (though the loop with sleep is not too bad).
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Just now I understand, what exactly happens. Nothing terrible, I am just confused that IDE doesn't warn (in other cases IDE is very talkative).

Sleeps. I also don't like a loop, but I don't see another way.
The app sends different parallel requests to web-server. Before each http-request the program checks access token, which lives a very short period.

I need to prevent executing of two "refreshtoken" in the same moment. In Windows I like to use CreateMutex. But what to do in B4A/B4I ?
 
Upvote 0

j_o_h_n

Active Member
Licensed User
Nothing terrible, I am just confused that IDE doesn't warn (in other cases IDE is very talkative)

I don't this think that this is something the IDE/Compiler would warn about.
From the compiler's point of view, I expect that this is no different to how you use any
other global variable?
 
Upvote 0
Top