Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
Ref
and Deferred
are coming from fs2, MVar
is coming from Monix (and of course from Haskell, although in Haskell you also have STM)
MVar
, separating the functionality into Ref
and Deferred
instead
Can't MVar in place of Ref?
Anyway if you do set/put
, it will break in the presence of concurrency
Ref.modify
Ref
is also lighter weight
Eq
variant sounds appealing, I could come up with a proposal
Deferred
is write-once
Ref
+ Deferred
you can implement structures that aren't
Semaphore
and Queue
in fs2 are implemented with Ref
+ Deferred
(used to be called Promise
)
MVar
allows you to do both at once
Ref
as something that could deal with concurrent state only
Deferred
is very simple: starts empty, becomes full, can't be emptied or modified again. get
on empty waits (asyncly), get on full immediately returns. complete
on empty unblocks the readers, complete
on full fails
MVar
gives a lot more ways to end up in deadlock
MVar
worker#1 -> mvar.put(1)
worker#2 -> mvar.put(2)
…
worker#n -> mvar.put(n)
// they all block asyncly if mvar is non-empty
// clients reading forever
client#1 -> mvar.take
client#2 -> mvar.take
…
client#n -> mvar.take
I imagine if all worker
s and client
s share the same mvar
instance we get something that looks like a queue