Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DontSuspend option #574

Merged
merged 5 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ lazy val `keywords-Match` =
lazy val `keywords-TryCatch` =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.dependsOn(Dsl, `keywords-Shift`, `keywords-Match`)
.dependsOn(Dsl, `keywords-Shift`, `keywords-Fence`, `keywords-Match`)

lazy val `keywords-TryCatchFinally` =
crossProject(JSPlatform, JVMPlatform)
Expand All @@ -89,6 +89,11 @@ lazy val `keywords-Suspend` =
.crossType(CrossType.Pure)
.dependsOn(Dsl)

lazy val `keywords-Fence` =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.dependsOn(Dsl)

lazy val `keywords-Return` =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
Expand Down Expand Up @@ -166,7 +171,7 @@ lazy val `keywords-Yield` =
Dsl,
`macros-Reset` % Test,
`keywords-Each` % Test,
`keywords-Shift` % Test,
`keywords-Shift` % Test
)

lazy val `keywords-Monadic` =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thoughtworks.dsl
package domains

import com.thoughtworks.dsl.macros.Reset
import com.thoughtworks.dsl.macros.Reset.Default.*
import com.thoughtworks.dsl.Dsl.{!!}
import org.scalatest.Assertion
Expand Down Expand Up @@ -34,7 +35,7 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
}
summon[
reified.type <:<
Typed[FlatMap[
Typed[Suspend[FlatMap[
Pure[n.type],
Match.WithIndex[(0), Pure[(0)]]
+:
Expand All @@ -45,7 +46,7 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
FlatMap[Shift[Task.TaskDomain, Int], Pure[Int]]
]]
+: Nothing
], Int]
]], Int]
]
Task {

Expand All @@ -70,15 +71,12 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
} else {
accumulator
})
summon[reified.type <:< Typed[
If[Pure[
Boolean
], Shift[
Task.TaskDomain,
Int
], Pure[Int]],
summon[reified.type <:< Typed[Suspend[If[Pure[
Boolean
], Shift[
Task.TaskDomain,
Int
]]
], Pure[Int]]], Int]]
Task {
if (i < 10000) {
!Shift(loop(i + 1, accumulator + i))
Expand Down Expand Up @@ -110,12 +108,40 @@ final class taskSpec extends AsyncFreeSpec with Matchers {

"*[Task] does not necessarily suspend or catch exceptions" in {
class MyException extends Exception
def task1: Task[Int] = *[Task] {
def task1: Task[Int] = new Reset {
type ShouldResetNestedFunctions = false
type DontSuspend = true
}.*[Task] {
throw new MyException
}
a[MyException] should be thrownBy task1
}

"rethrow" in Task.toFuture(Task {
class MyException extends Exception
val task1: Task[Int] = Task {
throw new MyException
}

val task2 = Task {
val v =
try {
try {
!Shift(task1)
"no exception"
} catch {
case myException: MyException =>
throw myException
}
} catch {
case myException: MyException =>
"my exception"
}
s"try: $v"
}
!Shift(task2) should be("try: my exception")
})

"try" in Task.toFuture(Task {
class MyException extends Exception
val task1: Task[Int] = Task {
Expand Down
Loading