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
Mark Tomko
@mtomko
great, I'm coming to the end of my day, but I'll read that code over and try to reframe things.
Thanks!
Fabio Labella
@SystemFw
you just need to figure out what is the right concurrent structure to hold that
Mark Tomko
@mtomko
oh, like Deferred (because there's no initial value) and Ref
Fabio Labella
@SystemFw
yeah, MVar might actually work here, and it's a simple enough case that it should be ok to use
and if it does, you can literally copy the definition of holdResource replacing SignallingRef with MVar
Mark Tomko
@mtomko
well, I think I was wrong about MVar. I must have confused it with Ref. I don't want a 1-element queue, because there's no guarantee that anyone will take - so I don't want to block on put if it's full.
Fabio Labella
@SystemFw
yeah, you could do it with a proper MVar update, which we don't have (because it's tough to use in most other cases which aren't this)
but basically if you wanted to use MVar for this
your update should take and then put, whereas your read side should read
Mark Tomko
@mtomko
yeah, I was debating that, too. Is that better than using Ref?
Fabio Labella
@SystemFw
with Ref[F, A] you won't be able to say "wait for the first element", and you'd need to pass a first element, at which point you could have used hold
you can do it with Ref[F, VerySimpleThingy[A]]
where VerySimpleThingy is a simple state machine with Deferred like the ones I described in my talk
Mark Tomko
@mtomko
got it. presumably with MVar I'd need to tryTake inside update, so that I didn't block if I had a new value to publish.
Fabio Labella
@SystemFw
basically FirstCall(wait: Deferred[F, A]) | SubsequentCalls(get: A)
no, you want take
Mark Tomko
@mtomko
I'll go back though - was that the talk about concurrency primitives in fs2, maybe NE Scala 2019?
Fabio Labella
@SystemFw
I have a better version, that one was misrecorded
ah, actually you're right about tryTake
what works with the first call does not for the next ones
another example of why MVar is tricky
Mark Tomko
@mtomko
Thanks! I was at NE Scala for the original but it's been a while. I'll watch the other talk and also study the documentation a bit. Thanks for the help!
Fabio Labella
@SystemFw
the Ref + Deferred version is pretty simple though
like I can probably sketch it out now if you need it
Mark Tomko
@mtomko
If you'd like, I'd be glad to see it, but I can also come back if I can't figure it out.
I feel bad nerdsniping you into a solution, but I'd also like to see it :)
Fabio Labella
@SystemFw
I can do it I think, it's one of the simplest
Mark Tomko
@mtomko
great! thanks so much!
Fabio Labella
@SystemFw
basically with this approach you want to model this sort of problems as a finite state machine
for this scenario you have two cases: the first call, where there is no value initially, and the subsequent calls where there is a new value that needs updating
the first scenario requires some waiting, in case the first get call arrives before the variable can be populated
waiting means having a deferred
so overall the state looks like this
sealed trait State[A]
case class FirstCall(wait: Deferred[F, A]) extends State[A]
case class NextCalls(v: A) extends State[A]
normally I put this as an inner class in the create method of the abstraction (I'll show you that in a bit), so that's why there is no F[_] parameter, it's normally in the outer definition
Mark Tomko
@mtomko
I'm with you so far
Fabio Labella
@SystemFw
then you want to write the transitions
well, I should specify that you have a Ref[F, State[A]] as your main component
Christopher Davenport
@ChristopherDavenport
What is first call parameterized?
That looks to lose the F
Deferred holds some F
Fabio Labella
@SystemFw
you need an initial value for that, which looks like
for {
  d <- Deferred[F, A]
  r <- Ref[F].of(FirstCall(d): State)
} yield r

@ChristopherDavenport do you mean

, so that's why there is no F[_] parameter, it's normally in the outer definition

let me just write the whole thing down, then we can talk about it, it's clearer
be back in 5
Mark Tomko
@mtomko
thanks!
Fabio Labella
@SystemFw
ah btw, there is one hard bit you need to think about in general, which is what to do when update fails. I'm going to write a buggy version that does not account for that, then we can discuss
Mark Tomko
@mtomko
oh, right, good point!