I tried to signify the problem and I make it worst. Lets give the complex code.
I'm calling a function like:
mySchedule(config, actorSystem.scheduler.schedule) {
...
}
the function is defined like:
def mySchedule(config: MyConfig, cb: (FiniteDuration, FiniteDuration) => (=> Unit) => Cancellable)(f : => Unit) = {
val initialDelay = ...
val interval = ...
cb(initialDelay, interval)(f)
}
For doing the test I was willing to do something like
def noop: Unit = {}
val promiseSchedule = Promise[(FiniteDuration, FiniteDuration, => Unit)]()
mySchedule(
config,
{... promiseSchedule.success((initialDelay, interval, f))}
)(noop)
promiseSchedule.future.value must be_==(...)
How do I make this work?
Try that:
def noop(): Unit = {}
val promiseSchedule = Promise[(Int, () => Unit)]()
// ...
promiseSchedule.success((1, noop))
The reason is because in a Tuple (just like in a case class) all members of the constructior are vals.
And it is not possible to store a by-name call in a val but only its value or a function.
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With