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

KNOLDUS-advt-sticker

Written by 

Charmy is a Software Consultant having experience of more than 1.5 years. She is familiar with Object Oriented Programming Paradigms and has familiarity with Technical languages such as Scala, Lagom, Java, Apache Solr, Apache Spark, Apache Kafka, Apigee. She is always eager to learn new concepts in order to expand her horizon. Her hobbies include playing guitar and Sketching.

1 thought on “Ingress to Monix-Execution: Scheduler

Leave a Reply

%d bloggers like this: