Skip to content

Commit

Permalink
util-core: Make Future.raiseWithin take a thunk Throwable
Browse files Browse the repository at this point in the history
Problem

Future.raiseWithin takes an Exception value as an argument which
is inconsistent with the other Future timer based API's and can
be costly since creating an exception often necessitates creating
a stacktrace.

Solution

Make the exception call-by-name.

JIRA Issues: CSL-7133

TBR=true

Differential Revision: https://phabricator.twitter.biz/D229559
  • Loading branch information
Bryce Anderson authored and jenkins committed Oct 22, 2018
1 parent cdf2b45 commit 9bde57c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
Unreleased
----------

* util-core: `c.t.u.Future.raiseWithin` methods now take the timeout exception as a call-by-name
parameter instead of a strict exception. ``PHAB_ID=D229559``

18.10.0
-------

Expand Down
4 changes: 2 additions & 2 deletions util-core/src/main/scala/com/twitter/util/Future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1595,15 +1595,15 @@ abstract class Future[+A] extends Awaitable[A] { self =>
*
* ''Note'': On timeout, the underlying future is interrupted.
*/
def raiseWithin(timeout: Duration, exc: Throwable)(implicit timer: Timer): Future[A] =
def raiseWithin(timeout: Duration, exc: => Throwable)(implicit timer: Timer): Future[A] =
raiseWithin(timer, timeout, exc)

/**
* Returns a new Future that fails if this Future does not return in time.
*
* ''Note'': On timeout, the underlying future is interrupted.
*/
def raiseWithin(timer: Timer, timeout: Duration, exc: Throwable): Future[A] = {
def raiseWithin(timer: Timer, timeout: Duration, exc: => Throwable): Future[A] = {
if (timeout == Duration.Top || isDefined)
return this

Expand Down

0 comments on commit 9bde57c

Please sign in to comment.