Skip to content

Commit

Permalink
added forgotten test file
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Sep 11, 2023
1 parent a9c37ef commit 949d513
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions compiler-plugin/testdata/set15pe/m3/TestUseResource.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cps.pe

import scala.annotation.experimental
import scala.concurrent.*
import scala.concurrent.duration.*
import org.junit.{Test,Ignore}

import cps.*
// import cps.testconfig.given


@experimental
class TestUseResource {

import scala.concurrent.ExecutionContext.Implicits.global

def openResource(name: String, logger: PEToyLogger): Resource[PureEffect,String] = {
Resource.Allocate(() =>
PureEffect.delay((name,
() => async[PureEffect](logger.log(s"close $name"))))
)
}


def openResourceDirect(name:String, logger: PEToyLogger)(using CpsDirect[[X]=>>Resource[PureEffect,X]]): String = {
await(openResource(name,logger))
}

@Test
def testResourceInterop() = {
val c = async[[X]=>>Resource[PureEffect,X]] {
val logger = PEToyLogger.make()
val r1 = await(openResource("r1", logger))
logger.log("inside")
logger
}
val c1 = Resource.run(c)
val c2 = PureEffect.unsafeRunFuture(c1)
val c3 = c2.map{ logger =>
assert(logger.__all() == List("inside", "close r1"))
}
val r = Await.ready(c3, 1.second)
}

}

0 comments on commit 949d513

Please sign in to comment.