Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Sep 05 2019 14:43
    @typelevel-bot banned @jdegoes
  • Jan 31 2019 21:17
    codecov-io commented #484
  • Jan 31 2019 21:08
    scala-steward opened #484
  • Jan 31 2019 18:19
    andywhite37 commented #189
  • Jan 31 2019 02:41
    kamilongus starred typelevel/cats-effect
  • Jan 30 2019 00:01
    codecov-io commented #483
  • Jan 29 2019 23:51
    deniszjukow opened #483
  • Jan 29 2019 23:37
  • Jan 29 2019 23:22
  • Jan 29 2019 20:26
    Rui-L starred typelevel/cats-effect
  • Jan 29 2019 18:01
    jdegoes commented #480
  • Jan 29 2019 17:04
    thomaav starred typelevel/cats-effect
  • Jan 28 2019 17:43
    asachdeva starred typelevel/cats-effect
  • Jan 28 2019 07:12
    alexandru commented #480
  • Jan 28 2019 05:45
    codecov-io commented #482
  • Jan 28 2019 05:35
    daron666 opened #482
  • Jan 27 2019 13:56
    codecov-io commented #481
  • Jan 27 2019 13:46
    lrodero opened #481
  • Jan 27 2019 05:47
    codecov-io commented #460
  • Jan 27 2019 05:37
    codecov-io commented #460
Jakub Kozłowski
so the above snippets should actually return an immutable clone of ServerBinding that doesn't include unbind.
or make it a Resource[F, Unit], which is actually fine :)
Ryan Zeigler
Jakub Kozłowski
a bit harder to do if your resource is ActorSystem.
Ryan Zeigler
i'm writing a wire protocol client that is derived from fs2.Socket which does expose a close but none of my higher things do
so the question occured to me
Jakub Kozłowski
yeah it still feels strange to me that it's there
Ross A. Baker
We ripped out shutdown functions on http4s resources when they became Resources. No regrets. I think it makes things simpler.
what does it mean So it is useful for suspending effects
What does suspending effects mean?
Gavin Bisesi
it means that you can construct an IO which wraps a side effect but doesn't execute it until the IO executes
val hi: IO[Unit] = IO(println("hi")) <- prints nothing when constructing hi
Thanks a loty
What does Asynchronous boundaries mean in context with https://typelevel.org/cats-effect/datatypes/io.html#concurrency-and-cancellation
Daniel Spiewak
an asynchronous boundary is usually something like a thread pool yield
like really anything that's going to take a callback, then later on invoke it
@djspiewak thanks a lot
Daniel Spiewak
Adrian Legaspi
just a question, why the cats-effect typelevel page doesn't have the same community announcements as the cats typelevel page?
Alexandru Nedelcu
@akilegaspi what community announcements are you referring to? They are different projects.
Jakub Kozłowski
Fabio's talk about fibers under the hood is online: https://youtu.be/x5_MmZVLiSM
yes! been waiting for this one.
Georgi Krastev
nice :tada:
Brian P. Holt

I'm trying to write a function (Deferred[F[_], A], A) => F[Fiber[F, Unit]]such that the deferred will be completed when the fiber is canceled. (I'm trying to prove in a test that a function that's given a fiber cancels it under certain circumstances.)

I was thinking I could use deferred.complete(a) as a CancelToken[F] value but that seems to randomly deadlock.

The version below works better than any other combination of shifts I've found, but it still fails eventually, so I'm missing something.

def completeTheDeferredOnCancel[F[_] : Concurrent : ContextShift, A](deferred: Deferred[F, A], a: A): F[Fiber[F, Unit]] =
  Concurrent[F].start(Concurrent[F].cancelable[Unit] { _ =>
    deferred.complete(a) *> ContextShift[F].shift
  }) <* ContextShift[F].shift
for {
  deferred <- Deferred[IO, Int]
  fiber <- completeTheDeferredOnCancel[IO, Int](deferred, value)
  _ <- fiber.cancel
  output <- deferred.get.timeout(1.second) // occasionally times out
} yield output == value

Any suggestions?

Jakub Kozłowski
how about completeTheDeferredOnCancel = Async[F].never.guarantee(deferred.complete(a)).start?
there's a catch though - if you cancel that immediately, it might never start and the finalizer might not run
so what we usually do is add another Deferred[F, Unit] as a latch. You complete that first thing in completeTheDeferredOnCancel and wait for it before cancelling
I just did that in a PR. let me link
Jakub Kozłowski
just wondering what you need the fiber for (outside). You don't use it other than for cancelling it, so I'll assume you don't need it to be part of the function
so, in your case:
def completeTheDeferredOnCancel[F[_]: Async, A](deferred: Deferred[F, A], a: A): F[Nothing] = {
  Async[F].never.guaranteeCase {
    //only complete if canceled
    case Canceled => deferred.complete(a)
    case _ => Applicative[F].unit

for {
  deferred <- Deferred[IO, Int]
  latch <- Deferred[IO, Unit]
  fiber <- (latch.complete(()) *> completeTheDeferredOnCance(deferred, value)).start
  _ <- latch.get
  _ <- fiber.cancel
  output <- deferred.get
} yield output == value
I believe this should work (but it's also 2am so I might be wrong)
and Async[F].never can be anything you want.
basically bracket/guarantee help a lot in handling cancelation. Unless you actually plan to call the callback given to you by the cancelable constructor (_ => in your code), I'd keep using these.
cancelable is mostly for cancelable async. If you don't use async, you probably don't need cancelable. @bpholt
Brian P. Holt
Gotcha, I'll play around with that. Thanks for the help!
Fabio Labella
@bpholt why do you need to do that?
cancel already waits for finalisers to complete
so after cancel, you know things are done
if you need to propagate that info concurrently (which doesn't look like you do in those examples), it should be enough to do fiber.cancel >> deferred.complete(())
Kai(luo) Wang
Is there a microlib providing integration of cats-effect with scalatest?
Something in the same spirit as IOApp
Michael Pilquist
Daniel has something but hasn’t added support for scalatest, only specs2 and minitest or something
Gabriel Volpe
@djspiewak was working on something like that, not sure if it supports scalatest though
Michael Pilquist
FS2 has its own bespoke integration, which I think works really well
Miles Sabin
I'd be interested in such a thing too.