Ingress to Monix-Execution: Scheduler

In the previous blog you learnt about Monix Task. Now lets dive into Monix Scheduler. Akka’s Scheduler that includes pretty heavy dependency whereas Monix Scheduler that provides a common API which is resuable.

For Monix Scheduler to work first we need to include the dependency which is:-

libraryDependencies += "io.monix" % "monix-execution_2.11" % "2.0-RC10"

Make sure that your Scala version is same as Monix version in your dependency. The Monix Scheduler can be a replacement for Scala’s ExecutionContext as:-

Schedule With a Delay

To schedule with a delay let say after 2 seconds it must be run:-

Scala-friendly Scheduler code:-

Schedule Repeatedly

If we want to schedule task repeatedly with an initial delay say 2 seconds and then with a fixed delay of say 3 seconds:-

Scala-friendly Scheduler code:-

Cancel Scheduler

We can cancel the scheduler any time we want to by using:-

Thanks For Reading!! 🙂

References:- Monix Official Documentation


This entry was posted in Scala and tagged , , , , . Bookmark the permalink.

One Response to Ingress to Monix-Execution: Scheduler

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s