nirmelamoud Member Dec 6, 2022 #1 Hi, 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
Hi, 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
Erel B4X founder Staff member Licensed User Longtime User Dec 7, 2022 #2 Yes: [B4X] Resumable subs that return values (ResumableSub) Upvote 0
nirmelamoud Member Dec 8, 2022 #3 Thanks, but not what I was asking, Im asking if there is a way to do this funca (1) ... ret = funcb() ... do something with ret ... funcb() .... http call in a sync way (wait for....) .... return job.getText like in Java for example, it sound like B4A automatically run funcb in a separate thread so you cant get value back in funca Upvote 0
Thanks, but not what I was asking, Im asking if there is a way to do this funca (1) ... ret = funcb() ... do something with ret ... funcb() .... http call in a sync way (wait for....) .... return job.getText like in Java for example, it sound like B4A automatically run funcb in a separate thread so you cant get value back in funca
Erel B4X founder Staff member Licensed User Longtime User Dec 8, 2022 #4 nirmelamoud said: like in Java for example Click to expand... There is no such feature in Java. Resumable subs are similar (but not exactly the same) to C# async / await feature. nirmelamoud said: it sound like B4A automatically run funcb in a separate thread so you cant get value back in funca Click to expand... 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. Code: Copy 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 Upvote 0
nirmelamoud said: like in Java for example Click to expand... There is no such feature in Java. Resumable subs are similar (but not exactly the same) to C# async / await feature. nirmelamoud said: it sound like B4A automatically run funcb in a separate thread so you cant get value back in funca Click to expand... 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. Code: Copy 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
nirmelamoud Member Dec 8, 2022 #5 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 Upvote 0
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
Erel B4X founder Staff member Licensed User Longtime User Dec 8, 2022 #6 nirmelamoud said: of course I can do that in Java, Click to expand... No, you can't. There is no equivalent feature in Java. Even trivial code such as this will be much more complicated in Java: Code: Copy For i = 1 To 10 btn.SetVisibleAnimated(100 * i, i Mod 2 = 0) Sleep(100 * i) Next And of course that you can't hold the main thread or touch the UI from a background thread. Upvote 0
nirmelamoud said: of course I can do that in Java, Click to expand... No, you can't. There is no equivalent feature in Java. Even trivial code such as this will be much more complicated in Java: Code: Copy For i = 1 To 10 btn.SetVisibleAnimated(100 * i, i Mod 2 = 0) Sleep(100 * i) Next And of course that you can't hold the main thread or touch the UI from a background thread.
nirmelamoud Member Dec 8, 2022 #7 of course, not meant to hold the UI thread, 5 ways to make HTTP requests in Java 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 HttpClientMore 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 Upvote 0
of course, not meant to hold the UI thread, 5 ways to make HTTP requests in Java 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 HttpClientMore 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
Erel B4X founder Staff member Licensed User Longtime User Dec 8, 2022 #8 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. Upvote 0
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.
nirmelamoud Member Dec 8, 2022 #9 I agree resumable is a nice feature , when I was talking about the java feature is to implement what I was asking about which is sync call to HTTP get Upvote 0
I agree resumable is a nice feature , when I was talking about the java feature is to implement what I was asking about which is sync call to HTTP get
OliverA Expert Licensed User Longtime User Dec 9, 2022 #10 nirmelamoud said: or with double wait for Click to expand... 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. Upvote 0
nirmelamoud said: or with double wait for Click to expand... 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.