Skip to content

Commit f815a8d

Browse files
authored
Merge pull request #574 from Atry/suspend-root
Add DontSuspend option
2 parents a9a62fb + 704d680 commit f815a8d

File tree

11 files changed

+325
-182
lines changed

11 files changed

+325
-182
lines changed

build.sbt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ lazy val `keywords-Match` =
6767
lazy val `keywords-TryCatch` =
6868
crossProject(JSPlatform, JVMPlatform)
6969
.crossType(CrossType.Pure)
70-
.dependsOn(Dsl, `keywords-Shift`, `keywords-Match`)
70+
.dependsOn(Dsl, `keywords-Shift`, `keywords-Fence`, `keywords-Match`)
7171

7272
lazy val `keywords-TryCatchFinally` =
7373
crossProject(JSPlatform, JVMPlatform)
@@ -89,6 +89,11 @@ lazy val `keywords-Suspend` =
8989
.crossType(CrossType.Pure)
9090
.dependsOn(Dsl)
9191

92+
lazy val `keywords-Fence` =
93+
crossProject(JSPlatform, JVMPlatform)
94+
.crossType(CrossType.Pure)
95+
.dependsOn(Dsl)
96+
9297
lazy val `keywords-Return` =
9398
crossProject(JSPlatform, JVMPlatform)
9499
.crossType(CrossType.Pure)
@@ -166,7 +171,7 @@ lazy val `keywords-Yield` =
166171
Dsl,
167172
`macros-Reset` % Test,
168173
`keywords-Each` % Test,
169-
`keywords-Shift` % Test,
174+
`keywords-Shift` % Test
170175
)
171176

172177
lazy val `keywords-Monadic` =

domains-Task/.jvm/src/test/scala/com/thoughtworks/dsl/domains/taskSpec.scala

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thoughtworks.dsl
22
package domains
33

4+
import com.thoughtworks.dsl.macros.Reset
45
import com.thoughtworks.dsl.macros.Reset.Default.*
56
import com.thoughtworks.dsl.Dsl.{!!}
67
import org.scalatest.Assertion
@@ -34,7 +35,7 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
3435
}
3536
summon[
3637
reified.type <:<
37-
Typed[FlatMap[
38+
Typed[Suspend[FlatMap[
3839
Pure[n.type],
3940
Match.WithIndex[(0), Pure[(0)]]
4041
+:
@@ -45,7 +46,7 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
4546
FlatMap[Shift[Task.TaskDomain, Int], Pure[Int]]
4647
]]
4748
+: Nothing
48-
], Int]
49+
]], Int]
4950
]
5051
Task {
5152

@@ -70,15 +71,12 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
7071
} else {
7172
accumulator
7273
})
73-
summon[reified.type <:< Typed[
74-
If[Pure[
75-
Boolean
76-
], Shift[
77-
Task.TaskDomain,
78-
Int
79-
], Pure[Int]],
74+
summon[reified.type <:< Typed[Suspend[If[Pure[
75+
Boolean
76+
], Shift[
77+
Task.TaskDomain,
8078
Int
81-
]]
79+
], Pure[Int]]], Int]]
8280
Task {
8381
if (i < 10000) {
8482
!Shift(loop(i + 1, accumulator + i))
@@ -110,12 +108,40 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
110108

111109
"*[Task] does not necessarily suspend or catch exceptions" in {
112110
class MyException extends Exception
113-
def task1: Task[Int] = *[Task] {
111+
def task1: Task[Int] = new Reset {
112+
type ShouldResetNestedFunctions = false
113+
type DontSuspend = true
114+
}.*[Task] {
114115
throw new MyException
115116
}
116117
a[MyException] should be thrownBy task1
117118
}
118119

120+
"rethrow" in Task.toFuture(Task {
121+
class MyException extends Exception
122+
val task1: Task[Int] = Task {
123+
throw new MyException
124+
}
125+
126+
val task2 = Task {
127+
val v =
128+
try {
129+
try {
130+
!Shift(task1)
131+
"no exception"
132+
} catch {
133+
case myException: MyException =>
134+
throw myException
135+
}
136+
} catch {
137+
case myException: MyException =>
138+
"my exception"
139+
}
140+
s"try: $v"
141+
}
142+
!Shift(task2) should be("try: my exception")
143+
})
144+
119145
"try" in Task.toFuture(Task {
120146
class MyException extends Exception
121147
val task1: Task[Int] = Task {

0 commit comments

Comments
 (0)