sub MySubC(aCount as Int)
DoWhile i < aCount
..do something..
Sleep(400)
i = i + 1
Loop
End Sub
sub MySubB
DoWhile i < count
... do something ...
Sleep(400)
MySubC(200)
... do something ...
Sleep(400)
i = i + 1
Loop
End Sub
In B4J (and B4i) the app is always running until it is killed. It is never paused. The resumable subs will be killed together with the process.and you exit the app before all 5 calls has finished. then you return to the app
Yes. You can see in the countdown example that there is a different resumable sub created with each click.Can there be more than one Sleep() loop running at the same time?
Yes.In other words, can they be nested?
That's true. It is the most important programming language improvement since the addition of classes in B4A v2.0.This feature looks like a small new one but it's a new super powerful feature
It is not related to the OS. It is a compiler feature.Agree, I was looking over the Android-documentation but could not find it unless I missed
I did not understand.There is no relation between different calls to PrintNumber.
Sub AppStart (Form1 As Form, Args() As String)
PrintNumber(3)
PrintNumber(2)
PrintNumber(1)
Log("After")
End Sub
Sub PrintNumber(i As Int)
Sleep(i) '<--------------
Log(i)
End Sub
This feature is similar to stackless coroutines or async / await in other programming languages.
It is not similar to a loop with DoEvents as the main thread is not caught in the sub. The sub context is stored and is later resumed.
Yes. Remember that the code with the While loop was just an example. Practically you just write the code as if it is handled sequentially (like any other code).I guess that if you need to stop the resumable sub you simply break out of the while loops
Probably yes.We can use this feature for B4J server handler and websocket handler, am I correct?
The timeout should be implemented in the code that raises the event. Nothing bad will happen if you wait for an event and it is never raised. The code will not block.Will it be possible to implement timeout?