Skip to content
Permalink
Browse files

Replace fixed thread pool with cached thread pool for example blockin…

…g execution context
  • Loading branch information...
mtomko committed Jun 3, 2019
1 parent 1ec01ab commit 0e2a534749fd03f4c9c46b8591c014b973eb2664
Showing with 6 additions and 6 deletions.
  1. +1 −1 README.md
  2. +2 −2 docs/ReadmeExample.md
  3. +3 −3 docs/src/ReadmeExample.md
@@ -82,7 +82,7 @@ import scala.concurrent.ExecutionContext
object Converter extends IOApp {
private val blockingExecutionContext =
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))))(ec => IO(ec.shutdown()))
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())))(ec => IO(ec.shutdown()))
val converter: Stream[IO, Unit] = Stream.resource(blockingExecutionContext).flatMap { blockingEC =>
def fahrenheitToCelsius(f: Double): Double =
@@ -23,7 +23,7 @@ import scala.concurrent.ExecutionContext
object Converter extends IOApp {
private val blockingExecutionContext =
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))))(ec => IO(ec.shutdown()))
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())))(ec => IO(ec.shutdown()))
val converter: Stream[IO, Unit] = Stream.resource(blockingExecutionContext).flatMap { blockingEC =>
def fahrenheitToCelsius(f: Double): Double =
@@ -64,7 +64,7 @@ implicit val cs: ContextShift[IO] = IO.contextShift(scala.concurrent.ExecutionCo
//note: this should be shut down when it's no longer necessary - normally that's at the end of your app.
//See the whole README example for proper resource management in terms of ExecutionContexts.
val blockingExecutionContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))
val blockingExecutionContext = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())
def fahrenheitToCelsius(f: Double): Double =
(f - 32.0) * (5.0/9.0)
@@ -12,7 +12,7 @@ import scala.concurrent.ExecutionContext
object Converter extends IOApp {
private val blockingExecutionContext =
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))))(ec => IO(ec.shutdown()))
Resource.make(IO(ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())))(ec => IO(ec.shutdown()))
val converter: Stream[IO, Unit] = Stream.resource(blockingExecutionContext).flatMap { blockingEC =>
def fahrenheitToCelsius(f: Double): Double =
@@ -52,7 +52,7 @@ implicit val cs: ContextShift[IO] = IO.contextShift(scala.concurrent.ExecutionCo
//note: this should be shut down when it's no longer necessary - normally that's at the end of your app.
//See the whole README example for proper resource management in terms of ExecutionContexts.
val blockingExecutionContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))
val blockingExecutionContext = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())
def fahrenheitToCelsius(f: Double): Double =
(f - 32.0) * (5.0/9.0)
@@ -112,4 +112,4 @@ Let's shut down the ExecutionContext that we allocated earlier.

```tut
blockingExecutionContext.shutdown()
```
```

0 comments on commit 0e2a534

Please sign in to comment.
You can’t perform that action at this time.