How would you resolve the following compilation er...
# server
m
How would you resolve the following compilation error?
I came up with:
Copy code
var future: ScheduledFuture<*> by Delegates.notNull()
future = heartbeatExecutor.scheduleAtFixedRate({
but wondering if there are more elegant solutions...
p
just throw cancellationexception inside the future?
👍 1
d
@muliyul, Your solution in theory has a race condition. The lambda may end up being called before the scheduleAtFixedRate returns, which would cause
future
to not actually be assigned yet. @Paul Griffith’s suggestion would work, according to the JavaDoc for scheduleAtFixedRate.
If any execution of the task encounters an exception, subsequent executions are suppressed
m
I don't see a mention of
CancellationException
in javadoc.
d
Any exception will do.
👍 1