File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
library/src/scala/concurrent/impl Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -28,9 +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 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
37
+ }
38
+
31
39
override def transform [S ](f : Try [T ] => Try [S ])(implicit executor : ExecutionContext ): Future [S ] = {
32
40
val p = new DefaultPromise [S ]()
33
- onComplete { result => p.complete(try f(result) catch { case NonFatal (t) => Failure (t) }) }
41
+ onComplete { result =>
42
+ try { p.complete(f(result)) } catch { case t : Throwable => completeWithFailure(p, t) }
43
+ }
34
44
p.future
35
45
}
36
46
@@ -42,7 +52,7 @@ private[concurrent] trait Promise[T] extends scala.concurrent.Promise[T] with sc
42
52
case fut if fut eq this => p complete v.asInstanceOf [Try [S ]]
43
53
case dp : DefaultPromise [_] => dp.asInstanceOf [DefaultPromise [S ]].linkRootOf(p)
44
54
case fut => p completeWith fut
45
- } catch { case NonFatal (t) => p failure t }
55
+ } catch { case t : Throwable => completeWithFailure(p, t) }
46
56
}
47
57
p.future
48
58
}
You can’t perform that action at this time.
0 commit comments