final def forwardInterruptsTo()

in util-core/src/main/scala/com/twitter/util/Promise.scala [562:592]


  final def forwardInterruptsTo(other: Future[_]): Unit =
    forwardInterruptsTo0(other, WaitQueue.empty)

  @tailrec private final def forwardInterruptsTo0(other: Future[_], wq: WaitQueue[A]): Unit = {
    // This reduces allocations in the common case.
    if (other.isDefined) continue(wq)
    else
      state match {
        case s: Transforming[A] =>
          if (!cas(s, new Transforming(WaitQueue.merge(wq, s.waitq), other)))
            forwardInterruptsTo0(other, wq)

        case waitq: WaitQueue[A] =>
          if (!cas(waitq, new Transforming(WaitQueue.merge(wq, waitq), other)))
            forwardInterruptsTo0(other, wq)

        case t: Try[A] /* Done */ => wq.runInScheduler(t)

        case s: Interruptible[A] =>
          if (!cas(s, new Transforming(WaitQueue.merge(wq, s.waitq), other)))
            forwardInterruptsTo0(other, wq)

        case p: Promise[A] /* Linked */ => p.forwardInterruptsTo0(other, wq)

        case s: Interrupted[_] =>
          if ((wq ne WaitQueue.Empty) &&
            !cas(s, new Interrupted(WaitQueue.merge(wq, s.waitq), s.signal)))
            forwardInterruptsTo0(other, wq)
          else other.raise(s.signal)
      }
  }