LucaMs Expert Licensed User Longtime User Mar 30, 2017 #41 I'm getting seasick! [moreover, too much code ]
ilan Expert Licensed User Longtime User Mar 30, 2017 #42 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?
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?
Widget Well-Known Member Licensed User Longtime User Mar 30, 2017 #43 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 Code: 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
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 Code: 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
Erel B4X founder Staff member Licensed User Longtime User Mar 30, 2017 #44 ilan said: and you exit the app before all 5 calls has finished. then you return to the app Click to expand... 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. Widget said: Can there be more than one Sleep() loop running at the same time? Click to expand... Yes. You can see in the countdown example that there is a different resumable sub created with each click. Widget said: In other words, can they be nested? Click to expand... Yes.
ilan said: and you exit the app before all 5 calls has finished. then you return to the app Click to expand... 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. Widget said: Can there be more than one Sleep() loop running at the same time? Click to expand... Yes. You can see in the countdown example that there is a different resumable sub created with each click. Widget said: In other words, can they be nested? Click to expand... Yes.
imbault Well-Known Member Licensed User Longtime User Mar 30, 2017 #45 This feature looks like a small new one but it's a new super powerful feature Congrats Erel for this
moster67 Expert Licensed User Longtime User Mar 30, 2017 #46 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!
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!
Erel B4X founder Staff member Licensed User Longtime User Mar 31, 2017 #47 imbault said: This feature looks like a small new one but it's a new super powerful feature Click to expand... That's true. It is the most important programming language improvement since the addition of classes in B4A v2.0. moster67 said: Agree, I was looking over the Android-documentation but could not find it unless I missed Click to expand... It is not related to the OS. It is a compiler feature.
imbault said: This feature looks like a small new one but it's a new super powerful feature Click to expand... That's true. It is the most important programming language improvement since the addition of classes in B4A v2.0. moster67 said: Agree, I was looking over the Android-documentation but could not find it unless I missed Click to expand... It is not related to the OS. It is a compiler feature.
D Deleted member 103 Guest Mar 31, 2017 #48 There is no relation between different calls to PrintNumber. Click to expand... I did not understand. Is the sequence then fixed as with random generator?
There is no relation between different calls to PrintNumber. Click to expand... I did not understand. Is the sequence then fixed as with random generator?
Erel B4X founder Staff member Licensed User Longtime User Mar 31, 2017 #49 Code: 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
Code: 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
moster67 Expert Licensed User Longtime User Mar 31, 2017 #50 So if you delayed the first one from 3 to 10 the new order will be 2 3 1 ??
moster67 Expert Licensed User Longtime User Mar 31, 2017 #52 LucaMs said: No. After 1 2 10 Click to expand... Yep That was what I meant but did not write
B bigbadfred Member Licensed User Longtime User Apr 2, 2017 #55 I Love it! Will be useful during downloads of xml files, avoiding spaghetti code without those callback subs.
I Love it! Will be useful during downloads of xml files, avoiding spaghetti code without those callback subs.
Diego Roman Member Licensed User Apr 3, 2017 #56 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. Last edited: Apr 3, 2017
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.
Martin Larsen Active Member Licensed User Longtime User Apr 3, 2017 #57 Erel said: 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. Click to expand... This is a very useful feature. I guess that if you need to stop the resumable sub you simply break out of the while loops. Is that correct?
Erel said: 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. Click to expand... This is a very useful feature. I guess that if you need to stop the resumable sub you simply break out of the while loops. Is that correct?
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2017 #58 Martin Larsen said: I guess that if you need to stop the resumable sub you simply break out of the while loops Click to expand... 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).
Martin Larsen said: I guess that if you need to stop the resumable sub you simply break out of the while loops Click to expand... 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).
B billzhan Active Member Licensed User Longtime User Apr 3, 2017 #59 We can use this feature for B4J server handler and websocket handler, am I correct? Will it be possible to implement timeout?
We can use this feature for B4J server handler and websocket handler, am I correct? Will it be possible to implement timeout?
Erel B4X founder Staff member Licensed User Longtime User Apr 3, 2017 #60 billzhan said: We can use this feature for B4J server handler and websocket handler, am I correct? Click to expand... Probably yes. billzhan said: Will it be possible to implement timeout? Click to expand... 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.
billzhan said: We can use this feature for B4J server handler and websocket handler, am I correct? Click to expand... Probably yes. billzhan said: Will it be possible to implement timeout? Click to expand... 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.