Android Question Resumable Subs - order of execution

luke2012

Well-Known Member
Licensed User
Longtime User
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 ?

Thanks in advance for your help.
Luca.
 

aeric

Expert
Licensed User
Longtime User
Try:
'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
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
'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
 
Upvote 0

Unobtainius

Active Member
Licensed User
Longtime User
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
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure about wait for in the initialize sub
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
 
Upvote 0
Top