tjensen
tjensen

Reputation: 77

How to create a simple pause/timeout in scala

I am working with some pre existing scala code, and I am trying to execute a specific portion of code after a delay of 30 seconds. Something similar in execution to setTimeout from javascript. What would be the simplest way to do this?

I have been looking at the aka.util.timeout class but I am very new to scala and akka and I am unsure how to implement it.

Upvotes: 1

Views: 875

Answers (1)

mohit
mohit

Reputation: 4999

I am not sure what you are asking, but if you are using akka, then you can use akka schedulers.

 system.scheduler().scheduleOnce(30 seconds, testActor, "foo");

testActor will contain your code which will run when the testActor receives foo message. There are lots of options for scheduler, you can run it once, every 30 seconds or so etc, and also, its will be a non blocking reactive code.

Upvotes: 6

Related Questions