I'm writing a server end program using Twitter Finagle. I do not use the full Twitter server stack, just the part that enables asynchronous processing (so Future, Function, etc). I want the Future objects to have timeouts, so I wrote this:
Future<String> future = Future.value(some_input).flatMap(time_consuming_function1);
future.get(Duration.apply(5, TimeUnit.SECONDS));
time_consuming_function1
runs for longer than 5 seconds. But future
doesn't time out after 5 seconds and it waits till time_consuming_function1
has finished.
I think this is because future.get(timeout)
only cares about how long the future
took to create, not the whole operation chain. Is there a way to timeout the whole operation chain?