Skip to content

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

Description

@sideeffffect

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: dotty-cps-async/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 dotty-cps-async/cps-async-connect#2 (comment)

/cc @rssh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions