Skip to content

Commit c2dee16

Browse files
authored
Merge pull request #12 from scala-steward/update/dotty-cps-async-0.9.0
Update dotty-cps-async to 0.9.0
2 parents 0ed09fe + 729f5ce commit c2dee16

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
name := "cats-effect-cps"
1818

19-
ThisBuild / baseVersion := "0.2"
19+
ThisBuild / baseVersion := "0.3"
2020

2121
ThisBuild / organization := "org.typelevel"
2222
ThisBuild / organizationName := "Typelevel"
@@ -63,7 +63,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
6363

6464
libraryDependencies ++= {
6565
if (isDotty.value)
66-
Seq("com.github.rssh" %%% "dotty-cps-async" % "0.8.1")
66+
Seq("com.github.rssh" %%% "dotty-cps-async" % "0.9.0")
6767
else
6868
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
6969
})

core/shared/src/main/scala-3/cats/effect/cps.scala

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616

1717
package cats.effect
1818

19-
import _root_.cps.{async, await, CpsAsyncMonad, CpsAwaitable, CpsMonad, CpsMonadPureMemoization}
19+
import _root_.cps.{async, await, CpsAsyncMonad, CpsAwaitable, CpsConcurrentEffectMonad, CpsMonad, CpsMonadPureMemoization}
2020

21-
import cats.effect.kernel.{Async, Concurrent, Sync}
21+
import cats.effect.kernel.{Async, Concurrent, Fiber, Sync}
22+
import cats.effect.kernel.syntax.all._
2223

2324
import scala.util.Try
2425

2526
object cps {
2627

27-
transparent inline def async[F[_]](using inline am: CpsMonad[F], F: Sync[F]): InferAsyncArg[F] =
28-
new InferAsyncArg[F]
29-
30-
final class InferAsyncArg[F[_]](using am: CpsMonad[F], F: Sync[F]) {
31-
transparent inline def apply[A](inline expr: A) =
32-
F.defer(_root_.cps.Async.transform[F, A](expr)(using am))
33-
}
28+
inline def async[F[_]](using inline am: CpsMonad[F]): _root_.cps.macros.Async.InferAsyncArg[F] =
29+
new _root_.cps.macros.Async.InferAsyncArg[F]
3430

3531
final implicit class AwaitSyntax[F[_], A](val self: F[A]) extends AnyVal {
3632
transparent inline def await(using inline am: CpsAwaitable[F]): A =
@@ -43,8 +39,25 @@ object cps {
4339
}
4440

4541
// TODO we can actually provide some more gradient instances here
46-
implicit def catsEffectCpsConcurrentMonad[F[_]](implicit F: Async[F]): CpsAsyncMonad[F] =
47-
new CpsAsyncMonad[F] {
42+
implicit def catsEffectCpsConcurrentMonad[F[_]](implicit F: Async[F]): CpsConcurrentEffectMonad[F] =
43+
new CpsConcurrentEffectMonad[F] {
44+
45+
type Spawned[A] = Fiber[F, Throwable, A]
46+
47+
def spawnEffect[A](op: => F[A]): F[Spawned[A]] =
48+
F.defer(op).start
49+
50+
def join[A](op: Spawned[A]): F[A] =
51+
op.joinWithNever
52+
53+
def tryCancel[A](op: Spawned[A]): F[Unit] =
54+
op.cancel
55+
56+
override def delay[A](x: => A): F[A] =
57+
Sync[F].delay(x)
58+
59+
override def flatDelay[A](x: => F[A]): F[A] =
60+
Sync[F].defer(x)
4861

4962
def adoptCallbackStyle[A](source: (Try[A] => Unit) => Unit): F[A] =
5063
F.async_(cb => source(t => cb(t.toEither)))

0 commit comments

Comments
 (0)