B4J Tutorial [B4X] Resumable Subs - Sleep / Wait For - Erel    Feb 22, 2018   (49 reactions) New video tutorial:
255570732
Resumable subs is a new feature added in B4J v5.50 / B4i v4.00 / B4A v7.00. It dramatically simplifies the handling of asynchronous tasks.
(This feature is a variant of stackless coroutines.)
The special feature of resumable subs is that they can be paused, without p B4A Code Snippet [B4X] Wait for multiple tasks to complete - Erel    Sep 06, 2023   (25 reactions) A pattern such as this one can be used when you want to run multiple resumable subs concurrently and wait for all of them to complete before continuing:
Dim status(1) As Int
Test1(status)
Test2(status)
Test3(status)
Do While status(0) < 3
Sleep(50)
Loop
Log("all B4A Tutorial [B4X] Resumable subs that return values (ResumableSub) - Erel    Aug 25, 2020   (39 reactions) Remember that that a call to Sleep or Wait For in a resumable sub causes the code flow to return to the parent.
Example:
Sub Button1_Click
Sum(1, 2)
Log("after sum")
End Sub
Sub Sum(a As Int, b As Int)
Sleep(100) 'this will cause the code flow to return to the parent
Log(a + b)
End Sub
Output:
B4J Tutorial [B4X] How Resumable Subs work - agraham    Jan 30, 2019   (27 reactions) Button1_Click in turn now calls Wait For on an event named ‘Complete’ which it expects to contain the actual return value from Sum which is an integer. After the invocation of Wait For it in turn immediately returns to the message loop which now has two Resumable Subs waiting for events and can now B4A Tutorial [B4X] Resumable subs and the index pattern - Erel    Nov 24, 2019   (26 reactions) Whenever the sub instance is resumed after Sleep or Wait For we check whether MyIndex, which is a local variable specific to each sub instance, is the same as the global Label1Index variable. If not we immediately return. Result: https://www.b4x..gif As you can see the label is updated correctly B4A Tutorial [B4X] OkHttpUtils2 with Wait For - Erel    Apr 11, 2021   (56 reactions) 256583317
Downloading resources is simpler with the new Resumable Subs feature.
Using Wait For we can wait for the JobDone event in the same sub that started the download.
No longer is it needed to have a single sub that handles all requests results.
Simplest example:
Dim j As HttpJob
j.Initiali B4A Tutorial [B4X] Features that Erel recommends to avoid - Erel    Dec 06, 2023   (89 reactions) Platform specific API -> Cross platform API:
This is of course relevant when there is a cross platform API. Some developers have a misconception that the cross platform features have drawbacks compared to the platform specific API.
Node / Pane / Button / ... -> B4XView
Canvas -> B4XCanvas
All kinds B4A Tutorial [B4X] SQL with Wait For - Erel    May 15, 2017   (21 reactions) The new resumable subs feature, introduced in B4J v5.50, B4i v4.00 and B4A v7.00 (to be soon released), makes it simpler to work with large data sets with minimum effect on the program responsiveness.
The new standard way to insert data is:
For i = 1 To 1000
sql.AddNonQueryToBatch("INSERT INTO B4A Code Snippet [B4X] Wait For the first task to complete - Erel    Mar 21, 2024   (12 reactions) You can replace the Sleep calls in the "test" subs with Wait Fors. For example:
BannerAd.LoadAd
WaitForSuccess (status)
WaitForFailure(status)
Do While status(0) = ""
Sleep(50)
Loop
Log("task completed: " & status(0))
Private Sub WaitForSuccess (Status() As String)
Wait B4A Question ? B4XTurtle - Examples for teachers and parents - Erel (first post)    May 04, 2020   (1 reaction) Like most objects in B4X, the dialog and the template need to be initialized once.
We handle the Touch event and check if Args.Down is True.
Line #12 calls the Wait For keyword. Any sub where Wait For or Sleep are called is a 'resumable sub'. This is an important feature of B4X. It is fully explaine Page: 1   2   3   4   5   6   7   Powered by ColBERT |