Thats my point. Notice that sleep(0) is the first sentence in the sub.The first one will immediately return to the calling sub and the flow in that sub continues.
The seconds one will wait for the Process finishes (if everything is implemented correctly.).
Watch the Video: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/
Yes...Thats my point. Notice that sleep(0) is the first sentence in the sub.
Still the waitfor will wait for the process to finish, even with no return?
Since the sub returns no value, you don't need the rest of the declarationHi.
Let's say I have a sub like this:
B4X:Sub Process Sleep(0) ''' long process End Sub
What's the difference in calling the function like this
Process
or that
Wait For (Process)complete (r As Object)
since the function does not return values.
The waitfor will wait the end of the sub, despite the sleep there? I mean, sleep means return, but its not true for waitfor? Thats my point.Yes...
Sleep(0) does not pause the rest of the sub code to be executed... While the wait for will do just that, wait for all of the code on the colled sub to be executed, and only then continue...
The fact that the called sub has no return value is not important since after that last codeline of the called sub is executed, the flow returns to the caller sub.
Furthermore, wait for is not wait forever... If that called sub takes more than expected to be executed, the wait for will be ignored and the sub will continue...
Whenever Sleep or Wait For are called, the current sub is paused. This is equivalent to calling Return.Sleep does not mean return, it means "pause for X milliseconds".
Can you show me a code example where a sub "returns" due to a wait for or a sleep (0)?Whenever Sleep or Wait For are called, the current sub is paused. This is equivalent to calling Return.
The code is not paused. See my code below.Whenever Sleep or Wait For are called, the current sub is paused. This is equivalent to calling Return.
See below.Can you show me a code example where a sub "returns" due to a wait for or a sleep (0)?
I have never come across a post or code showing this behaviour...
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
Log("Call Whithout wait for")
process(1)
Log("End call Whithout wait for")
Log("Call Whit wait for")
Wait For (process(2)) complete (r As Object)
Log("End call Whit wait for")
End Sub
Sub process(i As Int) As ResumableSub
Sleep(0)
Log("Start process " & i)
For x = 1 To 50000
' Just for the sake of the example.
' Yes, yes, I could use delay...
File.Exists(File.DirApp, "notfound")
Next
Log("End process " & i)
Return 0
End Sub
Call Whithout wait for
End call Whithout wait for
Call Whit wait for
Start process 1
End process 1
Start process 2
End process 2
End call Whit wait for
See above.May I interfere
I want to advice you experts (who owns a computer ) to create small examples in source code that we can play around with.
For example I studied an example by Cableguy with the use of Animation, so such examples with just two-three step in sequence will be extremely useful.
After all a working example kinda fits like a glove versus only talking. Documented and working nice and tidy commented code is the way of the Jedi programmer,
never forget I said it first haha