iOS Question Wait For behaviour

Discussion in 'iOS Questions' started by Semen Matusovskiy, May 24, 2019.

  1. Semen Matusovskiy

    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.
     

    Attached Files:

    Last edited: May 24, 2019
  2. j_o_h_n

    j_o_h_n 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?
    Code:
    Sub Test1 (Id As Int)

        commonInstance.RefreshTokens (
    Id)
        
    Wait For (commonInstance) RefreshTokensDone
        
    Log ("Wait For " & Id)
      
    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    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).
     
  4. Semen Matusovskiy

    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 ?
     
  5. j_o_h_n

    j_o_h_n Member Licensed User

    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?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice