I'm learning Java at the moment and I see some code that looks like this:
public interface Await {
boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException;
}
public Await spinServerUp() {
this.startServers()
return (timeout, timeUnit) -> countDownLatch.await(timeout, timeUnit);
}
Now, I understand that countDownLatch
waits for the threads to complete before continuing on.
My question is - how do parameters timeout
and timeunit
get passed to the Lambda expression? I can't find any usage examples on my end for this block of code that I'm reading, so I'm a bit confused.
I'm also not sure if I follow the spinServerUp()
method that well, I understand that it calls this.startServers()
then returns the Lambda expression - thus giving control to the Lambda expression. Why return the Lambda expression, though?
I've tried to do some research and reading, but I got more confused. Any clarifications would be appreciated