Skip to content

Commit 88d3c95

Browse files
Bryce Andersonjenkins
Bryce Anderson
authored and
jenkins
committed
util-core: c.t.u.Responder is a dead type
Problem We have a type called `Responder` that houses the methods that are already defined on Future. This does nothing but bloat the itable of `Promise`, which is the only implementation of the sealed `Responder` trait. Solution Fold the method definitions into `Promise` and call it a day. Differential Revision: https://phabricator.twitter.biz/D824830
1 parent ab73d64 commit 88d3c95

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Runtime Behavior Changes
3232

3333
* util: Bump version of Caffeine to 2.9.3. ``PHAB_ID=D815761``
3434

35+
Breaking API Changes
36+
~~~~~~~~~~~~~~~~~~~~
37+
38+
* util-core: The `c.t.util.Responder` trait has been removed. ``PHAB_ID=D824830``
39+
3540
22.1.0
3641
------
3742

util-core/src/main/scala/com/twitter/util/Promise.scala

+37-41
Original file line numberDiff line numberDiff line change
@@ -323,45 +323,6 @@ object Promise {
323323

324324
private val AlwaysUnit: Any => Unit = _ => ()
325325

326-
sealed trait Responder[A] { this: Future[A] =>
327-
protected final def continueAll(wq: WaitQueue[A]): Unit = {
328-
var ks = wq
329-
while (ks ne WaitQueue.Empty) {
330-
continue(ks.first)
331-
ks = ks.rest
332-
}
333-
}
334-
335-
protected def continue(k: K[A]): Unit
336-
337-
/**
338-
* Note: exceptions in responds are monitored. That is, if the
339-
* computation `k` throws a raw (ie. not encoded in a Future)
340-
* exception, it is handled by the current monitor, see
341-
* [[Monitor]] for details.
342-
*/
343-
def respond(k: Try[A] => Unit): Future[A] = {
344-
continue(new Monitored(Local.save(), k))
345-
this
346-
}
347-
348-
def transform[B](f: Try[A] => Future[B]): Future[B] = {
349-
val promise = interrupts[B](this)
350-
351-
continue(new FutureTransformer(Local.save(), f, promise))
352-
353-
promise
354-
}
355-
356-
protected def transformTry[B](f: Try[A] => Try[B]): Future[B] = {
357-
val promise = interrupts[B](this)
358-
359-
continue(new TryTransformer(Local.save(), f, promise))
360-
361-
promise
362-
}
363-
}
364-
365326
// PUBLIC API
366327

367328
/**
@@ -465,9 +426,44 @@ object Promise {
465426
* space leak is incurred from `flatMap` in the tail position since
466427
* intermediate promises are merged into the root promise.
467428
*/
468-
class Promise[A] extends Future[A] with Promise.Responder[A] with Updatable[Try[A]] {
429+
class Promise[A] extends Future[A] with Updatable[Try[A]] {
469430
import Promise._
470431

432+
private final def continueAll(wq: WaitQueue[A]): Unit = {
433+
var ks = wq
434+
while (ks ne WaitQueue.Empty) {
435+
continue(ks.first)
436+
ks = ks.rest
437+
}
438+
}
439+
440+
/**
441+
* Note: exceptions in responds are monitored. That is, if the
442+
* computation `k` throws a raw (ie. not encoded in a Future)
443+
* exception, it is handled by the current monitor, see
444+
* [[Monitor]] for details.
445+
*/
446+
final def respond(k: Try[A] => Unit): Future[A] = {
447+
continue(new Monitored(Local.save(), k))
448+
this
449+
}
450+
451+
final def transform[B](f: Try[A] => Future[B]): Future[B] = {
452+
val promise = interrupts[B](this)
453+
454+
continue(new FutureTransformer(Local.save(), f, promise))
455+
456+
promise
457+
}
458+
459+
final protected def transformTry[B](f: Try[A] => Try[B]): Future[B] = {
460+
val promise = interrupts[B](this)
461+
462+
continue(new TryTransformer(Local.save(), f, promise))
463+
464+
promise
465+
}
466+
471467
// Note: this will always be one of:
472468
// - WaitQueue (Waiting)
473469
// - Interrupted
@@ -776,7 +772,7 @@ class Promise[A] extends Future[A] with Promise.Responder[A] with Updatable[Try[
776772
*
777773
* @throws Promise.ImmutableResult if the Promise is already populated
778774
*/
779-
def update(result: Try[A]): Unit = {
775+
final def update(result: Try[A]): Unit = {
780776
updateIfEmpty(result) || {
781777
val current = Await.result(liftToTry)
782778
throw ImmutableResult(s"Result set multiple times. Value='$current', New='$result'")

0 commit comments

Comments
 (0)