Skip to content

Commit

Permalink
Allocate one parasitic EC per Dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Sep 11, 2023
1 parent d2759d5 commit 82b9933
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions std/shared/src/main/scala/cats/effect/std/Dispatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ trait Dispatcher[F[_]] extends DispatcherPlatform[F] {
}
}

private[this] lazy val parasitic: ExecutionContext = new ExecutionContext {
def execute(runnable: Runnable) = runnable.run()
def reportFailure(t: Throwable) = t.printStackTrace()
}

// package-private because it's just an internal utility which supports specific implementations
// anyone who needs this type of thing should use unsafeToFuture and then onComplete
private[std] def unsafeRunAsync[A](fa: F[A])(cb: Either[Throwable, A] => Unit): Unit = {
// this is safe because the only invocation will be cb
implicit val parasitic: ExecutionContext = new ExecutionContext {
def execute(runnable: Runnable) = runnable.run()
def reportFailure(t: Throwable) = t.printStackTrace()
}

unsafeToFuture(fa).onComplete(t => cb(t.toEither))
unsafeToFuture(fa).onComplete(t => cb(t.toEither))(parasitic)
}
}

Expand Down

0 comments on commit 82b9933

Please sign in to comment.