Future
As you can see in the test code, wsClient.url(testURL).get() returns Future; more precisely, it returns Future of Response (Future[Response]).
Future represents a piece of code executed asynchronously. The code starts its execution upon the creation of Future, without knowing when it will finish its execution.
So far, so good; but how can we get the result?
Before we answer this question, there are some important points to understand. What is the purpose of writing asynchronous code?
We write it to improve performance. Indeed, if the code is run in parallel, we can take advantage of the multiple cores that are available on modern CPUs. This is all fine, but in my program, I cannot parallelize every piece of code. Some pieces are dependent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access