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.
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
'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
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 ?
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 ?
Hi all, within a initialize of a class I run three resumable subs: "Download1", "Download2" and "Download3": 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize Download1 'Resumable Sub1 Download2 'Resumable Sub2 Download3 'Resumable Sub3...
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