Android Question Returning Value from Resumable Sub

DawningTruth

Active Member
Licensed User
I have a sub that uses a resumable sub to fetch website data. As you cannot return a value from a resumable sub, how do I get the value of the website data out of the sub.

Here is my code:

B4X:
Private Sub mySub
  
    FetchWebsite("https://duckduckgo.com", Array As String("q","test","t","hj","ia","web"))
    Wait For FetchWebsite_Complete

    'Somehow use myJob.GetString value

End Sub


Sub FetchWebsite(url As String, param() As String)
 
    Dim myJob As HttpJob
 
    myJob.Initialize("", Me)
    myJob.Download2(url,param)
    Wait For (myJob) JobDone (myJob As HttpJob)
    If myJob.Success Then
        Log(myJob.GetString)
    Else
        Log("Error: " & myJob.ErrorMessage)
    End If
    myJob.Release
 
    CallSubDelayed(Me, "FetchWebsite_Complete")
 
    'Somehow return myJob.GetString

End Sub

Any assistance is appreciated :)
 
Last edited:

Brandsum

Well-Known Member
Licensed User
I have a sub that uses a resumable sub to fetch website data. As you cannot return a value from a resumable sub, how do I get the value of the website data out of the sub.

Here is my code:

B4X:
Private Sub mySub
 
    FetchWebsite("https://duckduckgo.com", Array As String("q","test","t","hj","ia","web"))
    Wait For FetchWebsite_Complete

    'Somehow use myJob.GetString value

End Sub


Sub FetchWebsite(url As String, param() As String)
 
    Dim myJob As HttpJob
 
    myJob.Initialize("", Me)
    myJob.Download2(url,param)
    Wait For (myJob) JobDone (myJob As HttpJob)
    If myJob.Success Then
        Log(myJob.GetString)
    Else
        Log("Error: " & myJob.ErrorMessage)
    End If
    myJob.Release
 
    CallSubDelayed(Me, "FetchWebsite_Complete")
 
    'Somehow return myJob.GetString

End Sub

Any assistance is appreciated :)
B4X:
Private Sub mySub
 
    Wait For (FetchWebsite("https://duckduckgo.com", Array As String("q","test","t","hj","ia","web"))) complete(data As String)
    Log(data)

End Sub


Sub FetchWebsite(url As String, param() As String) As ResumableSub
 
    Dim myJob As HttpJob
     Dim data As String
    myJob.Initialize("", Me)
    myJob.Download2(url,param)
    Wait For (myJob) JobDone (myJob As HttpJob)
    If myJob.Success Then
        data = myJob.GetString
    Else
        data = myJob.ErrorMessage
    End If
    myJob.Release
    Return data
End Sub
 
Upvote 0

DawningTruth

Active Member
Licensed User
B4X:
Private Sub mySub
 
    Wait For (FetchWebsite("https://duckduckgo.com", Array As String("q","test","t","hj","ia","web"))) complete(data As String)
    Log(data)

End Sub


Sub FetchWebsite(url As String, param() As String) As ResumableSub
 
    Dim myJob As HttpJob
     Dim data As String
    myJob.Initialize("", Me)
    myJob.Download2(url,param)
    Wait For (myJob) JobDone (myJob As HttpJob)
    If myJob.Success Then
        data = myJob.GetString
    Else
        data = myJob.ErrorMessage
    End If
    myJob.Release
    Return data
End Sub

Thx, so much Brandsum.
 
Upvote 0
Top