@@ -615,8 +615,30 @@ Invoking the `future` construct uses a global execution context to start an asyn
615615Support for extending the Futures API with additional utility methods is planned.
616616This will allow external frameworks to provide more specialized utilities.
617617
618+
618619## Blocking
619620
621+ ### in a Future
622+
623+ As seen with the global ` ExecutionContext ` , it is possible to notify an ` ExecutionContext ` of a blocking call with the ` blocking ` construct.
624+ The implementation is however at the complete discretion of the ` ExecutionContext ` . While some ` ExecutionContext ` such as ` ExecutionContext.global `
625+ implement ` blocking ` by means of ` ManagedBlocker ` , some just do nothing:
626+
627+ implicit val ec = ExecutionContext.fromExecutor(
628+ Executors.newFixedThreadPool(4))
629+ Future{
630+ // here blocking serves only for documentation purpose
631+ blocking{blockingStuff() }
632+ }
633+
634+ Is equivalent to
635+
636+ Future{blockingStuff() }
637+
638+ The blocking code may also throw an exception. In this case, the exception is forwarded to the caller.
639+
640+ ### on a Future
641+
620642As mentioned earlier, blocking on a future is strongly discouraged
621643for the sake of performance and for the prevention of deadlocks.
622644Callbacks and combinators on futures are a preferred way to use their results.
@@ -656,17 +678,6 @@ The `Future` trait implements the `Awaitable` trait with methods
656678method ` ready() ` and ` result() ` . These methods cannot be called directly
657679by the clients-- they can only be called by the execution context.
658680
659- To allow clients to call 3rd party code which is potentially blocking
660- and avoid implementing the ` Awaitable ` trait, the same
661- ` blocking ` primitive can also be used in the following form:
662-
663- blocking{
664- potentiallyBlockingCall()
665- }
666-
667- The blocking code may also throw an exception. In this case, the
668- exception is forwarded to the caller.
669-
670681
671682
672683## Exceptions
0 commit comments