I've tried to work this out, but it seems that I must be expecting something that isn't possible.
I wrote this test code (with B4A V7.30):
Sub Activity_Resume
Private i As Int
For i = 1 To 5
Log("Iteration " & i)
Sub1(i)
Next
Log("Done")
End Sub
Sub Sub1(i As Int)
Log("Sub1 " & i & " start")
Wait For (Sub2(i)) Complete (Result As Boolean)
Log("Sub1 " & i & " finish")
End Sub
Sub Sub2 (i As Int) As ResumableSub
Log("Sub2 " & i & " start")
Sleep(3000)
Log("Sub2 " & i & " finish")
Return True
End Sub
The log screen shows this:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Iteration 1
Sub1 1 start
Sub2 1 start
Iteration 2
Sub1 2 start
Sub2 2 start
Iteration 3
Sub1 3 start
Sub2 3 start
Iteration 4
Sub1 4 start
Sub2 4 start
Iteration 5
Sub1 5 start
Sub2 5 start
Done
Then, after three seconds, it shows this:
Sub2 1 finish
Sub2 2 finish
Sub1 1 finish
Sub2 3 finish
Sub2 4 finish
Sub1 2 finish
Sub2 5 finish
Sub1 3 finish
Sub1 4 finish
Sub1 5 finish
What I was expecting (or rather hoping for) was something more like this:
Interation 1
Sub1 1 start
Sub2 1 start
(a three second delay here)
Sub2 1 finish
Sub1 1 finish
(and so on, four more times)
Is there any way I can implement a one second delay in my code, for testing purposes only, that doesn't block anything, but also doesn't return/stop until the delay is finished?
Regards,
Peter