Skip to content

Commit

Permalink
fix + add js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HollandDM committed Nov 7, 2024
1 parent 2d22939 commit 60a85a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
11 changes: 4 additions & 7 deletions kyo-core/js/src/main/scala/kyo/KyoAppPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ abstract class KyoAppPlatformSpecific extends KyoApp.Base[Async & Resource & Abo
maybePreviousAsync match
case Absent => ()
case Present(previousAsync) =>
val combinedFiberIO =
for
keepAliveFiber <- Clock.repeatWithDelay(1.hours)(())
previousFiber <- Async.run(previousAsync)
combineFiber <- Fiber.race(Seq(keepAliveFiber.get, previousFiber.get))
yield combineFiber
val _ = IO.Unsafe.run(Async.run(combinedFiberIO.get)).eval
val racedAsyncIO = Clock.repeatWithDelay(1.hours)(()).map { fiber =>
Async.race(Seq(fiber.get, previousAsync))
}
val _ = IO.Unsafe.run(Async.run(racedAsyncIO)).eval
)
end if
end run
Expand Down
32 changes: 26 additions & 6 deletions kyo-core/shared/src/test/scala/kyo/KyoAppTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import Tagged.*
import kyo.Clock.Deadline
import kyo.Clock.Stopwatch
import kyo.Clock.Unsafe
import kyo.internal.LayerMacros.Validated.succeed
import org.scalatest.compatible.Assertion
import scala.collection.mutable.ListBuffer
import scala.util.Try

class KyoAppTest extends Test:

Expand All @@ -31,15 +34,16 @@ class KyoAppTest extends Test:
runs <- ref.get
yield assert(runs == 3)
}
"multiple runs on JS" taggedAs jsOnly in run {
val x = new ListBuffer[Int]
object TestApp extends KyoApp:
"multiple runs on JS" taggedAs jsOnly in {
val x = new ListBuffer[Int]
val promise = scala.concurrent.Promise[Assertion]()
val app = new KyoApp:
run { IO(x += 1) }
run { IO(x += 2) }
run { IO(x += 3) }
end TestApp
TestApp.main(Array.empty)
assert(x == Seq(1, 2, 3))
run { IO(promise.complete(Try(assert(x.toList == List(1, 2, 3))))) }
app.main(Array.empty)
promise.future
}
"effects" taggedAs jvmOnly in {
def run: Int < (Async & Resource & Abort[Throwable]) =
Expand All @@ -55,6 +59,22 @@ class KyoAppTest extends Test:
import AllowUnsafe.embrace.danger
assert(KyoApp.Unsafe.runAndBlock(Duration.Infinity)(run) == Result.success(1))
}
"effects on JS" taggedAs jsOnly in {
val promise = scala.concurrent.Promise[Assertion]()
val app = new KyoApp:
run {
for
_ <- Clock.repeatAtInterval(1.second, 1.second)(())
i <- Random.nextInt
_ <- Console.println(s"$i")
_ <- Clock.now
_ <- Resource.ensure(())
_ <- Async.sleep(1.second)
yield promise.complete(Try(succeed))
}
app.main(Array.empty)
promise.future
}
"failing effects" taggedAs jvmOnly in {
def run: Unit < (Async & Resource & Abort[Throwable]) =
for
Expand Down

0 comments on commit 60a85a5

Please sign in to comment.