Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim res As Map = CreateMap()
Dim rss() As ResumableSub = Array As ResumableSub(S1(res), S2(res), S3(res))
Wait For (WaitForSubs(rss)) Complete (unused As Boolean)
Dim r1 As Int = res.Get("S1")
Log(r1)
End Sub
Sub WaitForSubs (rss() As ResumableSub) As ResumableSub
Dim completed As Boolean = False
Do While completed = False
completed = True
For Each rs As ResumableSub In rss
If rs.Completed = False Then completed = False
Next
Sleep(50)
Loop
Return True
End Sub
Sub S1 (Result As Map) As ResumableSub
Sleep(Rnd(10, 5000))
Result.Put("S1", 1) '1 is the result
Return True
End Sub
Sub S2 (Result As Map) As ResumableSub
Sleep(Rnd(10, 5000))
Result.Put("S2", 2)
Return True
End Sub
Sub S3 (Result As Map) As ResumableSub
Sleep(Rnd(10, 5000))
Result.Put("S3", 3)
Return True
End Sub