1616
1717package 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
2324import scala .util .Try
2425
2526object 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