I’m trying to reuse some module that uses monix.eval.Task
for async tasks.
My project uses scala.concurrent.Future
.
I'm trying to understand the best way to convert it to Future
with the least amount of damage.
The easiest way is to use an additional thread pool:
import monix.eval.Task
import monix.execution.Scheduler.Implicits.global
import scala.concurrent.Future
// Create a Monix Task
val monixTask: Task[String] = Task("Hello, Monix!")
// Convert the Task to a Future using toFuture
val scalaFuture: Future[String] = monixTask.toFuture
But I don't fully understand the performance implications.
- I already have
scala.concurrent.ExecutionContext
defined in the project. What are the implications of adding the globalmonix.execution.Scheduler
? - Where the tasks will actually be computed? With
ExecutionContext
orScheduler
? I'm guessing it queue up onScheduler
, have a small overhead of conversion, and then run onExecutionContext
?
The given module simply uses Task.deferFuture
on all the Future he receives.
The async tasks are IO tasks, having 300k~600k rpm.