Skip to content

Commit

Permalink
Merge pull request #12 from scala-steward/update/dotty-cps-async-0.9.0
Browse files Browse the repository at this point in the history
Update dotty-cps-async to 0.9.0
  • Loading branch information
djspiewak authored Jul 16, 2021
2 parents 0ed09fe + 729f5ce commit c2dee16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

name := "cats-effect-cps"

ThisBuild / baseVersion := "0.2"
ThisBuild / baseVersion := "0.3"

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

libraryDependencies ++= {
if (isDotty.value)
Seq("com.github.rssh" %%% "dotty-cps-async" % "0.8.1")
Seq("com.github.rssh" %%% "dotty-cps-async" % "0.9.0")
else
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
})
35 changes: 24 additions & 11 deletions core/shared/src/main/scala-3/cats/effect/cps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@

package cats.effect

import _root_.cps.{async, await, CpsAsyncMonad, CpsAwaitable, CpsMonad, CpsMonadPureMemoization}
import _root_.cps.{async, await, CpsAsyncMonad, CpsAwaitable, CpsConcurrentEffectMonad, CpsMonad, CpsMonadPureMemoization}

import cats.effect.kernel.{Async, Concurrent, Sync}
import cats.effect.kernel.{Async, Concurrent, Fiber, Sync}
import cats.effect.kernel.syntax.all._

import scala.util.Try

object cps {

transparent inline def async[F[_]](using inline am: CpsMonad[F], F: Sync[F]): InferAsyncArg[F] =
new InferAsyncArg[F]

final class InferAsyncArg[F[_]](using am: CpsMonad[F], F: Sync[F]) {
transparent inline def apply[A](inline expr: A) =
F.defer(_root_.cps.Async.transform[F, A](expr)(using am))
}
inline def async[F[_]](using inline am: CpsMonad[F]): _root_.cps.macros.Async.InferAsyncArg[F] =
new _root_.cps.macros.Async.InferAsyncArg[F]

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

// TODO we can actually provide some more gradient instances here
implicit def catsEffectCpsConcurrentMonad[F[_]](implicit F: Async[F]): CpsAsyncMonad[F] =
new CpsAsyncMonad[F] {
implicit def catsEffectCpsConcurrentMonad[F[_]](implicit F: Async[F]): CpsConcurrentEffectMonad[F] =
new CpsConcurrentEffectMonad[F] {

type Spawned[A] = Fiber[F, Throwable, A]

def spawnEffect[A](op: => F[A]): F[Spawned[A]] =
F.defer(op).start

def join[A](op: Spawned[A]): F[A] =
op.joinWithNever

def tryCancel[A](op: Spawned[A]): F[Unit] =
op.cancel

override def delay[A](x: => A): F[A] =
Sync[F].delay(x)

override def flatDelay[A](x: => F[A]): F[A] =
Sync[F].defer(x)

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

0 comments on commit c2dee16

Please sign in to comment.