in util-core/src/main/scala/com/twitter/util/Promise.scala [880:909]
protected final def link(target: Promise[A]): Unit = {
if (this eq target) return
state match {
case s: Transforming[A] =>
if (!cas(s, target)) link(target)
else target.forwardInterruptsTo0(s.other, s.waitq)
case waitq: WaitQueue[A] =>
if (!cas(waitq, target)) link(target)
else target.continue(waitq)
case value: Try[A] /* Done */ =>
if (!target.updateIfEmpty(value) && value != Await.result(target)) {
throw new IllegalArgumentException("Cannot link two Done Promises with differing values")
}
case s: Interruptible[A] =>
if (!cas(s, target)) link(target)
else target.setInterruptHandler0(s.handler, s.waitq)
case p: Promise[A] /* Linked */ =>
if (cas(p, target)) p.link(target)
else link(target)
case s: Interrupted[A] =>
if (!cas(s, target)) link(target)
else target.raise0(s.signal, s.waitq)
}
}