Composing Results
Responses in dispatch are wrapped up in a scala Future
. The Future represents the potential "result" of the asynchronous http call. The dispatch Future is obtained from a promise inside the dispatch library. dispatch makes an anysnchronous call, completes the promise, which then signals that the Future has a value available. async-http-client can return a java Future, but a java and scala Future
are different.
When managing responses there are a few ways to manage the Future
value as well as the body. This section is about composing results which is really about composing Future's. You can find a bounty of literature on composing Futures on the web and we are not try to repeat or summarize that corpus here.
There are a few topics though:
Future management with dispatch's Future's enhancements
async macro
Miscellaneous Topics
Retries
Interrupting requests (TODO)
Note that composing results really means composing the "containers" that hold our results, which in this case is a scala Future. This chapter will cover a few ways of composing Futures such as the use of scala async, however, there are libraries such as fetch
that have been created to compose functions that have high latency--which is often the case for http calls. These are covered in another chapter.
Last updated
Was this helpful?