Skip to content
Advertisement

Linkedin parseq. How to run task after task?

I’m using parseq framework for asynchronous computation.

Consider the following code. It first queries the content of google.com and then map the content to it’s length. Finally, the length is printed.

The problem is that only the first task is ran. Why?

JavaScript

Advertisement

Answer

I was able to solve your problem with the use of HttpClient instead of OkHttp .

Below are the overall maven dependencies that i used for this code:

JavaScript

JavaScript

Output:

JavaScript

This example is fully asynchronous. The home pages for StackOverflow , Google, and Ethereum are all fetched in parallel while the original thread has returned to the calling code. We used Tasks.par to tell the engine to parallelize these HTTP requests. Once all of the responses have been retrieved they are transformed into a int (string length)that is finally printed out.

Gist: https://gist.github.com/vishwaratna/26417f7467a4e827eadeee6923ddf3ae

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement