B4J Question Are CallSubDelayed events FIFO?

OliverA

Expert
Licensed User
Longtime User
If I call a method several times vial CallSubDelayed, will the execution of the events/the method be processed in FIFO order? If yes, can that be given as a guarantee (unless some program exception occurs)? If not, in what order will the methods be executed? A simple non-gui test seems to indicate FIFO, I'm just trying to get a clarification on this. Why? That would be one way to create a queue that is in order from another event (asyncstreams, mqtt, etc.) without needing to create a manual queue to store items and tracking the queue pointer.

B4X:
Sub AppStart (Args() As String)
   Dim x As Int
   Dim y As Int = 25
   For x = 1 To y
       Log($"Calling thesub# ${x}"$)
       CallSubDelayed3(Me, "thesub", x, y)
   Next
   StartMessageLoop
End Sub

Sub thesub(someval As Int, stopval As Int)
   Log($"Call# ${someval}"$)
   If(stopval = 0) Then
       StopMessageLoop
   End If
End Sub
[code]
Output:
[quote]
Calling thesub# 1
Calling thesub# 2
Calling thesub# 3
Calling thesub# 4
Calling thesub# 5
Calling thesub# 6
Calling thesub# 7
Calling thesub# 8
Calling thesub# 9
Calling thesub# 10
Calling thesub# 11
Calling thesub# 12
Calling thesub# 13
Calling thesub# 14
Calling thesub# 15
Calling thesub# 16
Calling thesub# 17
Calling thesub# 18
Calling thesub# 19
Calling thesub# 20
Calling thesub# 21
Calling thesub# 22
Calling thesub# 23
Calling thesub# 24
Calling thesub# 25
Call# 1
Call# 2
Call# 3
Call# 4
Call# 5
Call# 6
Call# 7
Call# 8
Call# 9
Call# 10
Call# 11
Call# 12
Call# 13
Call# 14
Call# 15
Call# 16
Call# 17
Call# 18
Call# 19
Call# 20
Call# 21
Call# 22
Call# 23
Call# 24
Call# 25
[/quote]
 
Top