Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala + Play, how to get a duration from the HOCON configuration?

Imagine I have a Duration value defined in my application.conf file. The documentation says it can parse Durations, but I can't see how.

timeout = 60 milliseconds

Can I parse it directly as a duration value? Ideally I would like to do something like this

val timeout = current.configuration.getMilliseconds("timeout")
(myActor ? GiveMeSomething)(timeout).mapTo[...]

but timeout is an Option[Long]. Thanks for any tips.

like image 774
ticofab Avatar asked Nov 30 '25 02:11

ticofab


1 Answers

Play's configuration does support Duration, FiniteDuration and other Scala types. Use: configuration.get[FiniteDuration]("path.to.duration") The Configuration.get function takes an implicit ConfigLoader[A]. Play comes with a lot of implementations and easy to add additional ones.

like image 181
Joost den Boer Avatar answered Dec 02 '25 15:12

Joost den Boer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!