I have a sub that use Wait For in order to call rest interface, I want to make it a sync call and return value, can I do that ?
or do I have to use call chain at the end and call other function with the 'return' value
No additional threads are created for resumable subs.
The way to implement the logic that you are describing is with subs that return ResuableSub + Wait For.
B4X:
Sub FuncA
Wait For (FuncB) Complete (Result As Something)
Log(Result)
End Sub
Sub FuncB As ResumableSub
Dim j As HttpJob
...
Dim res As String = j.GetString
j.Release
Return res
End Sub
of course I can do that in Java, but regardless, what you are saying is that I can't do that in basic and I need to use callback-like functionality or with double wait for - ok
thanks
Twilio posts cloud communications trends, customer stories, and tips for building scalable voice and SMS applications with Twilio's APIs.
www.twilio.com
Java 11 HttpClient
More than twenty years after HttpURLConnection we had Black Panther in the cinemas and a new HTTP client added to Java 11: java.net.http.HttpClient. This has a much more logical API and can handle HTTP/2, and Websockets. It also has the op
I was talking about the resumable subs feature. This is not specific to http requests. It is a language feature which allows you to deal with event-driven asynchronous code in almost the same way that you will do with synchronous code.
Even a double Wait For does not block. That's the beauty of Wait For, you don't have to worry about grinding the event queue to a halt. Looking at the doc for the Java 11 implementation, both HttpClient.send and CompletableFuture.get are fully blocking, therefore forcing you to use threads in cases where the return may take a while (since at that point, the event queue would be blocked). Now, if you are looking at a full blocking HTTP request that stalls out the event queue, then you'll have to come up with something else.