Android Question Resumable functions

LucaMs

Expert
Licensed User
Longtime User
I'm trying to create a FUNCTION like:
B4X:
Sub DownloadFile(FileName As String) As ResumableSub
    Dim Result As Boolean

    Dim HJob As Httpjob
    ' ...
    ' ...
    Wait For (HJob) Jobdone(jobResult As HttpJob)
    If jobResult.Success...
    '...
    Result = ---
    ' ...
    Result = ---
    '...

    Return Result
End Sub

but I get this exception:
java.lang.RuntimeException: Cannot parse: (RemoteResumableSub) anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub@21f819e0 as boolean

It seems (to me) that "Wait For", returns the control to the calling code also returning an Httpjob object (jobResult) to it (in this case), while the function would like to return a boolean.


How should I create a function like this?



Thank you
 

LucaMs

Expert
Licensed User
Longtime User
Can you post the code that calls this sub?
Synthetically, what I think may be relevant:

B4X:
Sub ChooseLanguage_Click ' <--- resumable

   Dim cd As CustomLayoutDialog
   cd.ShowAsync("Choose language"
   Wait For Dialog_Ready (DialogPanel As Panel)
   
   Wait For CLVDialog_ItemClick (Index As Int, Value As Object)


    If DownloadDB(DBFileToDownload) Then ' DownloadDB should be a resumable function


End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
See step #3 from the tutorial:

The steps required are:

1. Add As ResumableSub to the resumable sub signature.
2. Call Return with the value you like to return.
3. In the calling sub, call the resumable sub with Wait For (<sub here>) Complete (Result As <matching type>)

Example from the tutorial:
B4X:
Sub Button1_Click
   Wait For(Sum(1, 2)) Complete (Result As Int) '<---------------------------------
   Log("result: " & Result)
   Log("after sum")
End Sub

Sub Sum(a As Int, b As Int) As ResumableSub
   Sleep(100)
   Log(a + b)
   Return a + b
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I know!!!

I answered to a question about Resumable subs which return values, pointing to your turorial!

My question is like if you wanted to insert an httpjob, with a wait for, in your sub Sum.

Forse io dovrei scrivere in italiano, affinché si capisca :)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes, you code is correct, I know, but there are differences in my code, to my intentions.

I try to explaing using the example (from your tutorial) you posted in #8.

B4X:
Sub Button1_Click
   Wait For(Sum(1, 2)) Complete (Result As Int) '<---------------------------------
   Log("result: " & Result)
   Log("after sum")
End Sub

Sub Sum(a As Int, b As Int) As ResumableSub
   Sleep(100)

   Wait for http job to get Factor from Internet
   Return (a + b) * Factor
End Sub

I changed something, as you can see (pseudo-code). If you did something like that, you would get the exception I posted in my first post.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
That's exactly what I was saying, Erel: that is, I'm stupid!

In this line:
If DownloadDB(DBFileToDownload) Then ' DownloadDB should be a resumable function

I pretended to receive the result, even though I know how to use a resumable that returns a result.

The problem is that I'm stressed, especially this period; or... I'm really stupid (this is much more likely :p).



I'm sorry for all this :(.


Thank you, Erel.
 
Upvote 0
Top