Code Monkey home page Code Monkey logo

cats-effect-cps's People

Contributors

alexandru avatar armanbilge avatar baccata avatar djspiewak avatar kamilkloch avatar lhns avatar rssh avatar scala-steward avatar typelevel-steward[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cats-effect-cps's Issues

Analogue to await, but for Resource (instead of IO)

It would be great, if there were support for using Resource with cats-effect-cps. Could look something like this

import cats.effect.cps._

async[IO] {
  val results1 = talkToServer("request1", None).await
  IO.sleep(100.millis).await

  // openResource: (String, Option[Data]) => Resource[IO, Data]
  val results2 = openResource("request2", Some(results1.data)).awaitResource

  if (results2.isOK) {
    writeToFile(results2.data).await
    IO.println("done!").await
    true
  } else {
    IO.println("abort abort abort").await
    false
  }
}

awaitResource is pretty bad name for this, but can't think of anything better at the moment. Over at dotty-cps-async, I recommended ! for IO and ~ for Resource: rssh/dotty-cps-async#43 (comment)

The motivation is that using Resource is a bit unergonomic, especially if there are many of them, because it requires the programmer to nest the blocks in use.
image

Related discussion about Resource at rssh/cps-async-connect#2 (comment)

/cc @rssh

Sync support if possible

Since doobie.ConnectionIO just can provide summon[Sync[ConnectionIO]], so I can't simply use cats-effect-cps in ConnectionIO. Is there any support if possible?

Scala 3 Support

It would be helpful to downstream consumers if we could provide Scala 2 and Scala 3 support in a single API.

Different performance between Scala2 and Scala3 in `async[Resource[IO, *]]`

val resource1 = async[Resource[IO, *]] {
  r1.await
}
val resource2 = async[Resource[IO, *]] {
  r2.await
}
val http4sServerResource = for {
  r1 <- resource1
  r2 <- resource2
} yield r1.exec(r2)

def run(args: List[String]): IO[ExitCode] = http4sServerResource.useForever.as(ExitCode.Success)

It seems that resource1 and resource2 is already use when the block of async { } is ended. So when r1.exec(r2) the resource is closed.

And in Scala3 r1.exec(r2) can exec succeed.

Support for Monad Transformer stacks?

I initially tried out this library with success in an CE3 IO based project.

In some modules I use monad stacks such as WriterT over IO (with cats-mtl).

When I try to use a stack with await, I get a compile error about

/* missing */
[error]    |        summon[
[error]    |          cps.CpsMonadContext[
[error]    |            [_] =>>
[error]    |              cats.data.WriterT[cats.effect.IO,
[error]    |                cats.data.Chain[LogRecord], _]
[error]    |          ]
[error]    |        ]

Im confident that Async is available for WriterT over IO, but Im unsure if I should expect CpsMonadContext to be derived for a monad stack? I note the readme example is for just plain IO.

Add a counter to "stateMachine$async" name

I think the following won't compile:

val a = async(io.await)
val b = async(io.await)

Since we use the same type name for everything. Macros may be doing some clever sanitization thing though which saves us.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.