@@ -28,15 +28,19 @@ private[concurrent] trait Promise[T] extends scala.concurrent.Promise[T] with sc
28
28
import scala .concurrent .Future
29
29
import scala .concurrent .impl .Promise .DefaultPromise
30
30
31
- private [this ] final def wrapFailure (t : Throwable ): Throwable = {
32
- if (NonFatal (t)) t
33
- else if (t.isInstanceOf [InterruptedException ]) new ExecutionException (" Boxed InterruptedException" , t)
34
- else throw t
31
+ private [this ] final def completeWithFailure (p : Promise [_], t : Throwable ): Unit = {
32
+ if (NonFatal (t)) p.complete(Failure (t))
33
+ else if (t.isInstanceOf [InterruptedException ]) {
34
+ if (p.tryComplete(Failure (new ExecutionException (" Boxed InterruptedException" , t))))
35
+ Thread .currentThread.interrupt()
36
+ } else throw t
35
37
}
36
38
37
39
override def transform [S ](f : Try [T ] => Try [S ])(implicit executor : ExecutionContext ): Future [S ] = {
38
40
val p = new DefaultPromise [S ]()
39
- onComplete { result => p.complete(try f(result) catch { case t : Throwable => Failure (wrapFailure(t)) }) }
41
+ onComplete { result =>
42
+ try { p.complete(f(result)) } catch { case t : Throwable => completeWithFailure(p, t) }
43
+ }
40
44
p.future
41
45
}
42
46
@@ -48,7 +52,7 @@ private[concurrent] trait Promise[T] extends scala.concurrent.Promise[T] with sc
48
52
case fut if fut eq this => p complete v.asInstanceOf [Try [S ]]
49
53
case dp : DefaultPromise [_] => dp.asInstanceOf [DefaultPromise [S ]].linkRootOf(p)
50
54
case fut => p completeWith fut
51
- } catch { case t : Throwable => p.failure(wrapFailure(t) ) }
55
+ } catch { case t : Throwable => completeWithFailure(p, t ) }
52
56
}
53
57
p.future
54
58
}
0 commit comments