@@ -618,26 +618,37 @@ This will allow external frameworks to provide more specialized utilities.
618618
619619## Blocking
620620
621- ### in a Future
621+ Futures are generally asynchronous and do not block the underlying execution threads.
622+ However, in certain cases, it is necessary to block.
623+ We distinguish two forms of blocking the execution thread:
624+ invoking arbitrary code that blocks the thread from within the future,
625+ and blocking from outside another future, waiting until that future gets completed.
626+
627+
628+ ### Blocking inside a Future
622629
623630As seen with the global ` ExecutionContext ` , it is possible to notify an ` ExecutionContext ` of a blocking call with the ` blocking ` construct.
624631The 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:
632+ implement ` blocking ` by means of a ` ManagedBlocker ` , some execution contexts such as the fixed thread pool:
633+
634+ ExecutionContext.fromExecutor(Executors.newFixedThreadPool(x))
635+
636+ will do nothing, as shown in the following:
626637
627638implicit val ec = ExecutionContext.fromExecutor(
628639 Executors.newFixedThreadPool(4))
629640Future{
630- // here blocking serves only for documentation purpose
631641 blocking{blockingStuff() }
632642}
633643
634- Is equivalent to
644+ Has the same effect as
635645
636646Future{blockingStuff() }
637647
638648The blocking code may also throw an exception. In this case, the exception is forwarded to the caller.
639649
640- ### on a Future
650+
651+ ### Blocking outside the Future
641652
642653As mentioned earlier, blocking on a future is strongly discouraged
643654for the sake of performance and for the prevention of deadlocks.
0 commit comments