Hi all,
within a initialize of a class I run three resumable subs: "Download1", "Download2" and "Download3":
B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Download1 'Resumable Sub1
Download2 'Resumable Sub2
Download3 'Resumable Sub3
End Sub
Sub Download1
Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
'code...
End Sub
Sub Download2
Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
'code...
End Sub
Sub Download3
Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
'code...
End Sub
I need these three subroutines to be executed in the exact sequence in which they are written.
So Download2 will be executed only after Download1 has finished its execution and so on.
How to do this ?
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Download1 'Resumable Sub1
End Sub
Sub Download1
Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
'code...
Download2 'Resumable Sub2
End Sub
Sub Download2
Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
'code...
Download3 'Resumable Sub3
End Sub
Sub Download3
Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
'code...
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
Wait For (Download1) Complete (result As boolean) 'Resumable Sub1
Wait For (Download2) Complete (result As boolean) 'Resumable Sub2
Wait For (Download3) Complete (result As boolean) 'Resumable Sub3
End Sub
Sub Download1 As ResumableSub
Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
'code...
Return True
End Sub
Sub Download2 As ResumableSub
Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
'code...
Return True
End Sub
Sub Download3 As ResumableSub
Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
'code...
Return True
End Sub
I'm not sure about wait for in the initialize sub
When in doubt about anything log(<this part of the process>) will allow you follow the execution order in the logs window
That's true. The compiler will throw an error as the class initialize sub cannot be a resumable sub.
B4X:
Public Sub Initialize
DownloadAll
End Sub
Private DownloadAll
Wait For (Download1) Complete (result As boolean) 'Resumable Sub1
Wait For (Download2) Complete (result As boolean) 'Resumable Sub2
Wait For (Download3) Complete (result As boolean) 'Resumable Sub3
End Sub
Sub Download1 As ResumableSub
Wait For (GetIDs (ID1, user, psw)) Complete (result1 As List)
'code...
Return True
End Sub
Sub Download2 As ResumableSub
Wait For (GetIDs (ID2, user, psw)) Complete (result2As List)
'code...
Return True
End Sub
Sub Download3 As ResumableSub
Wait For (GetIDs (ID3, user, psw)) Complete (result3 As List)
'code...
Return True
End Sub
First of all, thanks for your replies, @aeric@Star-Dust@Unobtainius and @Erel ! Top forum and top developers
So I try to update the code following your suggestions.