Skip to content

Commit ff4dff6

Browse files
committed
Reuse TrampolineContinuation for exception handling in throwableContinuationDsl
1 parent 57b7dda commit ff4dff6

File tree

1 file changed

+6
-29
lines changed
  • Dsl/src/main/scala/com/thoughtworks/dsl

1 file changed

+6
-29
lines changed

Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,20 @@ private[dsl] trait LowPriorityDsl1 { this: Dsl.type =>
6767

6868
private[dsl] trait LowPriorityDsl0 extends LowPriorityDsl1 { this: Dsl.type =>
6969

70-
// // FIXME: Shift
71-
// implicit def continuationDsl[Keyword, LeftDomain, RightDomain, Value](
72-
// implicit restDsl: Dsl.Original[Keyword, LeftDomain, Value],
73-
// shiftDsl2: Dsl.Original[Shift[LeftDomain, RightDomain], LeftDomain, RightDomain]
74-
// ): Dsl.Original[Keyword, LeftDomain !! RightDomain, Value] = {
75-
// new Dsl.Original[Keyword, LeftDomain !! RightDomain, Value] {
76-
// def cpsApply(keyword: Keyword, handler: Value => LeftDomain !! RightDomain): LeftDomain !! RightDomain = {
77-
// (continue: RightDomain => LeftDomain) =>
78-
// restDsl.cpsApply(keyword, { a =>
79-
// restDsl2.cpsApply(handler(a), continue)
80-
// })
81-
// }
82-
// }
83-
// }
84-
8570
private def throwableContinuationDsl[Keyword, LeftDomain, Value](implicit
8671
restDsl: Dsl.Searching[Keyword, LeftDomain, Value]
8772
): Dsl[Keyword, LeftDomain !! Throwable, Value] = Dsl {
88-
(keyword, handler) => continue =>
73+
(keyword, handler) => (continue: Throwable => LeftDomain) =>
8974
restDsl(
9075
keyword,
91-
// Use `new` to support the `return`
92-
new (Value => LeftDomain) {
93-
def apply(value: Value): LeftDomain = {
94-
val protectedContinuation =
95-
try {
96-
handler(value)
97-
} catch {
98-
case NonFatal(e) =>
99-
return continue(e)
100-
}
101-
// FIXME: Shift[Domain, Throwable]
102-
protectedContinuation(continue)
103-
}
76+
{ value =>
77+
TrampolineContinuation { () =>
78+
handler(value)
79+
}(continue)
10480
}
10581
)
10682
}
83+
10784
given [Keyword, LeftDomain, Value](using
10885
Dsl.IsStackSafe[LeftDomain],
10986
Dsl.Searching[Keyword, LeftDomain, Value]

0 commit comments

Comments
 (0)