Hi all,
I have a Servicemodule with HTTP-jobs, called HTTPservice.
All subs in there are resumable and they are sent two arguments in the call.
Sometimes I need to wait for the Service to complete, sometimes I don't need to wait.
Now I wonder which way is the best to solve this?
See below code.
In version 1, I call the Resumable Service and have a global xSender specifying where to return.
Either it is Activity1a or 1b. In the end of the service I check where to callback to.
In version 2, I call the service and then wait for the service to do everything with the Do While Not-loop.When the service is ready it sets the (Global) ServiceReady = True and then the code continues.
In version 3, I have tried to use Wait For but since the service is in another module it doesn't work as it is written here in the code. I've tried to add the "HTTPservice" but either it's SyntaxError or too many thing or...
Is there a way to use Wait For and call another module?
Should I use Wait For to call another Sub in the same module and that Sub uses CallSubDelayed3(... ?
In version 4, it's just a normal call without need to wait for it to complete.
So my question is this:
I want to use one Resumable Sub even if I need to wait or not.
It will be called from many different other Subs, from activities or services.
Sometimes I need to wait for it to complete and sometimes I don't.
What is the best solution to use?
(There might be errors in the code here and it might not be the best way to do things... But I'm asking since I want to learn)
I have a Servicemodule with HTTP-jobs, called HTTPservice.
All subs in there are resumable and they are sent two arguments in the call.
Sometimes I need to wait for the Service to complete, sometimes I don't need to wait.
Now I wonder which way is the best to solve this?
See below code.
In version 1, I call the Resumable Service and have a global xSender specifying where to return.
Either it is Activity1a or 1b. In the end of the service I check where to callback to.
In version 2, I call the service and then wait for the service to do everything with the Do While Not-loop.When the service is ready it sets the (Global) ServiceReady = True and then the code continues.
In version 3, I have tried to use Wait For but since the service is in another module it doesn't work as it is written here in the code. I've tried to add the "HTTPservice" but either it's SyntaxError or too many thing or...
Is there a way to use Wait For and call another module?
Should I use Wait For to call another Sub in the same module and that Sub uses CallSubDelayed3(... ?
In version 4, it's just a normal call without need to wait for it to complete.
So my question is this:
I want to use one Resumable Sub even if I need to wait or not.
It will be called from many different other Subs, from activities or services.
Sometimes I need to wait for it to complete and sometimes I don't.
What is the best solution to use?
(There might be errors in the code here and it might not be the best way to do things... But I'm asking since I want to learn)
B4X:
Sub Activity1a ' Version1a. Call and wait for callback
xSender = "Activity1a"
CallSubDelayed3(HTTPservice,"Service1",Lat,Lon)
Wait For Service_Ready
End Sub
Sub Activity1b ' Version1b. Call and wait for callback
xSender = "Activity1b"
CallSubDelayed3(HTTPservice,"Service1",Lat,Lon)
Wait For Service_Ready
End Sub
Sub Activity2 ' Version2. Call and wait for ServiceReady=True in a loop
CallSubDelayed3(HTTPservice,"Service1",Lat,Lon)
Do While Not(ServiceReady = True)
Sleep(0)
Loop
End Sub
Sub Activity3 ' Version3. Only Wait For, waiting for a return result
Wait For(Service1(Lat, Lon)) Complete (Ready as String)
End Sub
Sub Activity4 ' Version4. Call resumable sub and don't wait
CallSubDelayed3(HTTPservice,"Service1",Lat,Lon)
End Sub
'In Servicemodule HTTPservice
Public Sub Service1 (Latstring As String, Lonstring As String) As ResumableSub
Dim SendString As String
SendString = "https:xxxxxxxxx"
job1.Download(SendString)
Wait For (job1) JobDone(job1 As HttpJob)
If job1.Success Then
' Code....
End If
Result = "OK"
If xSender="Activity1a" Then 'Use a name of sub instead of Me beacause sender (Me) don't fit in call to sub
xSender=""
CallSubDelayed("Activty1a", "Service_Ready") 'Activity1a will get the return
Else
If xSender="Activity1b" Then
xSender=""
CallSubDelayed("Activty1b", "Service_Ready") 'Activity1b will get the return
Else
Return Result
End If
End If
End Sub