iOS Question B4i and OkHttpUtils2 with Wait For

imbault

Well-Known Member
Licensed User
Longtime User
I have problem with the Wait For in B4i, it goes back to the calling procedure instead of waiting for the Job:
So I tried with a sample from


B4X:
Sub btnSend_Click
    DownloadQuote
    log("Over")
End Sub


Sub DownloadQuote
    Dim j As HttpJob
    j.Initialize("", Me) 'name is empty as it is no longer needed
    j.Download("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        'The result is a json string. We parse it and log the fields.
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim quotes As List = jp.NextArray
        For Each quot As Map In quotes
            Log("Title: " & quot.Get("title"))
            Log("Content: " & quot.Get("content"))
        Next
    End If
    j.Release
End Sub

Gives me :
Over
And not Title and Content from DownloadQuote

Any help, please
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
B4X:
Sub btnSend_Click
    Wait For (DownloadQuote) Complete (Success As Boolean)
    If Success Then
        Log("Over")
    End If
End Sub

Sub DownloadQuote As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me) 'name is empty as it is no longer needed
    j.Download("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        'The result is a json string. We parse it and log the fields.
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim quotes As List = jp.NextArray
        For Each quot As Map In quotes
            Log("Title: " & quot.Get("title"))
            Log("Content: " & quot.Get("content"))
        Next
    End If
    j.Release
    Return j.Success
End Sub
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…