B4J Question Resumable Subs

ThRuST

Well-Known Member
Licensed User
Longtime User
I am trying to call three subs from a mainsub as a chain. It is important that every sub completes before the mainsub continues. So what's wrong with this example? I'm not sure about the Sleep(1000) will be safe enough, since each sub might take longer than the other. What I want to do is to download data with jOkHttpUtils2 from a MySQL database. Once all jobs are complete it may continue.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
  
    MainSub
  
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub MainSub
  
    Log("MainSub started")
    FirstSub
    Wait For FirstSub_Complete
    SecondSub
    Wait For SecondSub_Complete
    ThirdSub
    Wait For ThirdSub_Complete
    Log("Completed")
  
End Sub

Sub FirstSub
  
    Log("FirstSub started")
    SecondSub
    Wait For SecondSub_Complete
    Log("FirstSub completed")
  
End Sub

Sub SecondSub
  
    Log("SecondSub started")
    Sleep(1000)
    Log("SecondSub completed")
    CallSubDelayed(Me, "SecondSub_Complete")
  
End Sub

Sub ThirdSub
  
    Log("ThirdSub started")
    Sleep(2000)
    Log("ThirdSub completed")
    CallSubDelayed(Me, "ThirdSub_Complete")
  
End Sub

Somehow the ThirdSub is never logged, and either is Log("Completed").
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I found another post that seems more related to what I need, resumable subs with jOkHttpUtils2 library. Which I found >here<
It awakes the question which way is the best solution. Or we can experiment with a way that works. Even a timer will do the trick.
 
Upvote 0
Top