pekko/akka-docs-dev/rst/scala/http/routing-dsl/directives/future-directives/onComplete.rst

29 lines
954 B
ReStructuredText
Raw Normal View History

.. _-onComplete-:
onComplete
==========
Evaluates its parameter of type ``Future[T]``, and once the ``Future`` has been completed, extracts its
result as a value of type ``Try[T]`` and passes it to the inner route.
Signature
---------
.. includecode2:: /../../akka-http/src/main/scala/akka/http/scaladsl/server/directives/FutureDirectives.scala
:snippet: onComplete
Description
-----------
The evaluation of the inner route passed to a onComplete directive is deferred until the given future
has completed and provided with a extraction of type ``Try[T]``.
To handle the ``Failure`` case automatically and only work with the result value, use :ref:`-onSuccess-`.
To complete with a successful result automatically and just handle the failure result, use :ref:`-completeOrRecoverWith-`, instead.
Example
-------
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/FutureDirectivesExamplesSpec.scala
:snippet: onComplete