Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 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
Fabio Labella
@SystemFw
but all the code you've posted compiles for me, so maybe you can clarify what you're looking for a bit?
Michael Zuber
@mgzuber
yeah things compile fine
Fabio Labella
@SystemFw
ah ok
Michael Zuber
@mgzuber
but when I run using completeDeferredGen I get java.lang.AbstractMethodError
Fabio Labella
@SystemFw
I think you just have the wrong versions lying around
Michael Zuber
@mgzuber
whereas when I run with completeDeferred I get the expected output on the console
Fabio Labella
@SystemFw
e.g. you have Monix 2 and cats-effect 1.0
Michael Zuber
@mgzuber
mmm, I'm using Monix 3-RC1
but that depends on cats-effect-0.10
that could be the problem...
Fabio Labella
@SystemFw
that's it then
Michael Zuber
@mgzuber
yeah okay, that's a pain
off to the monix chat!
thanks for your help @SystemFw
Loïc Girault
@lgirault
Is there a reason why there is no method such asdef updateF(f: A => F[A]): F[Unit] for a Ref[F[_], A] ?
or do I miss a way to achieve it using the other methods ?
Or maybe I'm using the wrong tool for my task
Gavin Bisesi
@Daenyth
that seems trivially definable in your own code
smaller surface area in foundational libraries is a good thing
oh wait but => F[A]
hmm
Loïc Girault
@lgirault
yeah there is def update(f: A => A): F[Unit]
Gavin Bisesi
@Daenyth
problem being that get+update is not atomic
Loïc Girault
@lgirault
and its a get an set atomic. my "trivial" definition would lose atomicity
Gavin Bisesi
@Daenyth
yeah
I realized that after I said it
Loïc Girault
@lgirault
^_^
yeah I was like "wow did I miss something" ?
Gavin Bisesi
@Daenyth
the race condition prone version is trivial :awesome:
Loïc Girault
@lgirault
ok, I'll sleep on this one
maybe that can make an interesting PR if it's doable
johnw
@johnw

I've implemented Effect for my newtype class MyTask[E](toTask: monix.Task[E]) I did this in the following way:

class MyTaskEffect(effect: Effect[Task]) extends Effect[MyTask] { 
   /* implement the 9 methods that are uimplemented*/  
   override def runAsync[A](fa: MyTask[A])(cb: Either[Throwable, A] => IO[Unit]): IO[Unit] =
    effect.runAsync(fa.task)(cb)
//...
}

You instantiate an instance of the newtype like this:

 def create[C](
      initial: C
  )(implicit TaskEffect: Effect[Task], MyTaskEffect: Effect[MyTask]): MyTask[MyTaskEffectWithContext[C]] =
    Ref[MyTask, C](initial)(MyTaskEffect).map { initialRef =>
      new MyTaskEffectWithContext[C](TaskEffect, initialRef)
    }

Is there a better option?

Gavin Bisesi
@Daenyth
/shrug
check the laws
if it's good, it's good
johnw
@johnw
It seems to be lawful. I wasn't sure if there was some magic way of doing this sort of thing.
Fabio Labella
@SystemFw
@lgirault not doable
you can either make a version that risks a stale update
or one that repeats an effect a non-deterministic amount of times
but can't make a general one that works
in many cases, you can change your design/logic to not require that (e.g. by introducing a Deferredto avoid duplicating work), or you can use a Semaphore as a lock, so that you're free to do whatever you want in the critical section
Gavin Bisesi
@Daenyth
might even be something you could do with Signal or something depending on application logic needs
Fabio Labella
@SystemFw
but the general A => F[A] can't be done
we already tried a long time ago :P
(you can have one of the two versions above in your own code, for example when the effect is idempotent, but it's too risky to be in the public api imho)
Ross A. Baker
@rossabaker
I wanted that A => F[A] on Ref while working on an idle timeout yesterday, and came to the same conclusion. I ended up back on an imperative solution, but I want to revisit it. I think @ChristopherDavenport might find it useful as ember matures.
The desire being a timeout that can be "reset" by cancelling the current sleep and starting over before it fires.
Christopher Davenport
@ChristopherDavenport
You mean a locked ref?
Should be able to get something capable of it with a Semaphore. However you need to bar any modification options until F[A] returns.
Its definitely not something that generally should see much use.