mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
Add a few notes on Cancellable to the LLRC and HLRC docs. (#45912)
Add a section to both the low level and high level client documentation on asynchronous usage and `Cancellable` added for #44802 Co-Authored-By: Lee Hinman <dakrone@users.noreply.github.com>
This commit is contained in:
parent
60f40d7638
commit
030d43a76a
@ -154,3 +154,23 @@ executes the request. For example, this is the place where you'd specify a
|
||||
`NodeSelector` to control which node receives the request. See the
|
||||
<<java-rest-low-usage-request-options,low level client documentation>> for
|
||||
more examples of customizing the options.
|
||||
=== Asynchronous usage
|
||||
|
||||
All of the the methods across the different clients exist in a traditional synchronous and
|
||||
asynchronous variant. The difference is that the asynchronous ones use asynchronous requests
|
||||
in the REST Low Level Client. This is useful if you are doing multiple requests or are using e.g.
|
||||
rx java, Kotlin co-routines, or similar frameworks.
|
||||
|
||||
The asynchronous methods are recognizable by the fact that they have the word "Async" in their name
|
||||
and return a `Cancellable` instance. The asynchronous methods accept the same request object
|
||||
as the synchronous variant and accept a generic `ActionListener<T>` where `T` is the return
|
||||
type of the synchronous method.
|
||||
|
||||
All asynchronous methods return a `Cancellable` object with a `cancel` method that you may call
|
||||
in case you want to abort the request. Cancelling
|
||||
no longer needed requests is a good way to avoid putting unnecessary
|
||||
load on Elasticsearch.
|
||||
|
||||
Using the `Cancellable` instance is optional and you can safely ignore this if you have
|
||||
no need for this. A use case for this would be using this with e.g. Kotlin's `suspendCancellableCoRoutine`.
|
||||
|
||||
|
@ -338,6 +338,12 @@ the underlying http client. On the server side, this does not automatically
|
||||
translate to the execution of that request being cancelled, which needs to be
|
||||
specifically implemented in the API itself.
|
||||
|
||||
The use of the `Cancellable` instance is optional and you can safely ignore this
|
||||
if you don't need it. A typical usecase for this would be using this together with
|
||||
frameworks like Rx Java or the Kotlin's `suspendCancellableCoRoutine`. Cancelling
|
||||
no longer needed requests is a good way to avoid putting unnecessary
|
||||
load on Elasticsearch.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-async-cancel]
|
||||
|
Loading…
x
Reference in New Issue
Block a user