iOS Question Resumeable subs - need simple way

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

I need to add a fragment, which sends information to webserver and waits results, in one subroutine, let's name it 'DD'.
A problem is that I have enough long chains. Let's say subroutine AA calls subroutine BB, which calls 'CC', which calls 'DD'.

AA, BB, CC, DD previously was not resumeable. As I understand, I can do
B4X:
Sub AA
      BB
     Wait For eventBB
End Sub

Sub BB
      CC
     Wait For eventCC
      CallSubDelayed (Me, "eventBB")
End Sub

Sub CC
      DD
     Wait For eventDD
     CallSubDelayed (Me, "eventCC")
End Sub

Sub DD
    Msgbox2 ("Msg2", "Question", Title, Array ("Yes", "No"))
    Wait For Msg2_Click (stringButtonText As String)
    CallSubDelayed (Me, "eventDD")
End Sub

It's not comfortable and I am afraid to lose some chains.

Somebody knows more simple way ?
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Why not this:

Wait for in httpjob:
Sub OnlyOneSubNeeded

dim hj as HttpJob
hj.Initialize("", Me)
hj.Download("https://fromaserver.com/getresults.aspx")

Wait For (hj) JobDone(hj as HttpJob)

'Manipulate hj Results'

End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub ConnectToServer
    Wait For (AAA) Complete (result As boolean) 'Resumable Sub1
    Wait For (BBB) Complete (result As boolean) 'Resumable Sub2
    Wait For (CCC) Complete (result As boolean) 'Resumable Sub3
End Sub

Sub AAA As ResumableSub
    Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
    'code...
    Return True
End Sub

Sub BBB As ResumableSub
    Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
    'code...
    Return True
End Sub

Sub CCC As ResumableSub
    Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
    'code...
    Return True
End Sub

or
B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub ConnectToServer
    AAA 'Resumable Sub1
End Sub

Sub AAA
    Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
    'code...
    BBB 'Resumable Sub2
End Sub

Sub BBB
    Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
    'code...
    CCC 'Resumable Sub3
End Sub

Sub CCC 
    Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
    'code...
End Sub
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Imagine OnlyOneSubNeeded at the end of chain.

Subroutine AA calls subroutine BB, which calls OnlyOneSubNeeded.

If to do nothing subroutine BB will continue when OnlyOneSubNeeded executes Wait For
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
@Star-Dust

Very interesting Do you mean that I can replace all calls of my subroutine JSON_subCreate by Wait For (JSON_subCreate) Complete (...) ?
A subroutine sends Complete event, when exits ?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust

Very interesting Do you mean that I can replace all calls of my subroutine JSON_subCreate by Wait For (JSON_subCreate) Complete (...) ?
A subroutine sends Complete event, when exits ?
Yes. See this thread:

 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I made an expeiment. Of course, Wait For () Complete () is more comfortable than using CallSubDelay.

Meanwhile Complete keeps one subroutine only.

B4X:
Sub aa
    bb    
    Log ("AA")    
End Sub

Sub bb    
    Wait For (cc) Complete (result As Boolean)
    Log ("BB")        
End Sub

Sub cc As ResumableSub    
    Msgbox2 ("Msg", "Question", "Title", Array ("Yes", "No"))
    Wait For Msg_Click (stringButtonText As Object)
    Log ("CC")
    Return True
End Sub

Let's call subroutine aa. Output will be AA CC BB instead of desired CC BB AA.
To receive correct sequence it's necessary to correct subroutine aa also (what is not interesting).

B4X:
Sub aa
    
    Wait For (bb) Complete (result As Boolean)
    Log ("AA")
    
End Sub


Sub bb As ResumableSub 
    
    Wait For (cc) Complete (result As Boolean)
    Log ("BB")
    Return True    
    
End Sub

Sub cc As ResumableSub
    
    Msgbox2 ("Msg", "Question", "Title", Array ("Yes", "No"))
    Wait For Msg_Click (stringButtonText As Object)
    Log ("CC")
    Return True

End Sub
 
Upvote 0
Top