twitter/util

Future.raiseWithin(duration) creates TimeoutException proactively

jpbempel opened this issue · 3 comments

Future.raiseWithin(duration) creates TimeoutException proactively

Expected behavior

Future.raiseWithin should creates TimeoutException lazily

Actual behavior

Future.raiseWithin creates TimeoutException for each call which is most of the time useless, but inefficient because creating an exception like this calls fillInStackTrace which build the stack trace associated to the exception object

Steps to reproduce the behavior

calling raiseWithin(duration)

Suggestion:

in raiseWithin signature should take exc: => Throwable instead of just exc: Throwable to lazily pass the exception creation where it is really needed.

Thanks

@jpbempel, that seems like a good idea to me with the small caviate that it will break Java users. Let me see how it looks internally and we can go from there.

Looks like there are a few use cases internally, but it looks like not so much that we shouldn't do it. I'll take a run at this.

This should be fixed in 9bde57c which unfortunately just missed the release window.