this is really amazing @Erel.
i have 1 question please. what will happen if you start that action (like in post #40)
and you exit the app before all 5 calls has finished. then you return to the app. will they continue from where it stopped when you exit the app? something like a timer?
Can there be more than one Sleep() loop running at the same time?
In other words, can they be nested?
In this example MySubB has a Sleep() loop that calls MySubC that has its own Sleep() loop.
TIA
B4X:
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.
In B4A (Android) there are some nuisances related to the activity life cycle.
Agree, I was looking over the Android-documentation but could not find it unless I missed it. Maybe it will be a B4A exclusive,
It is really more amazing Erel can implement it also for B4i (iOS) and B4J
He never stops to surprise me!
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
Each call of PrintNumber is not dependent on other calls.
The first call will print 3 after 3ms. The second will print 2 after 2ms and the third will print 1 after 1ms.
They are called one after another immediately, so the output will be:
1
2
3
Thank you. Is a powerful improvement and Sleep function is very useful.
Since I know B4J I love it!. Is more simple than other languajes and more fast create really cool and useful aplications and process. Please continue making improvement to B4J. and please avoid to make the code so difficult to understand and write, keep it easy.
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).
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.