-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.0 Release blocker? Suspicious code in ConnectionStream class #118
Comments
Hi @mberndt123 , Thanks for raising your concerns here. You are right about that However, your other assumptions are wrong, let me explain why.
Have you tried doing this? It doesn't happen because the functions are RT.
You can try creating as many interpreters of |
Hi @gvolpe, thanks for responding. However I don't believe this is fixed.
I have tried it just now, and it does happen as I describe it. Here's a quick and dirty test I've written: it should "foobar" in {
val cfg = Fs2RabbitConfig(
"localhost",
5672,
"/",
1000,
false,
None,
Some("guest"),
Some("guest"),
false
)
val s = new ConnectionStream[IO](cfg)
(for {
_ <- s.acquireConnection
_ <- s.acquireConnection
} yield ()).unsafeRunSync()
} I have also inserted a |
Well, you are calling Anyway the Users shouldn't be creating a The library only exposes the Does that answer your question? |
Sure, I do expect two connections to be acquired. However that doesn't require creating two different
Well, that was for simplicity, but as a user I could also do
Right, but it also create a new |
Oh that's what you really meant. Sure, I think you're right here. Looking more into |
Hi,
I noticed some code in the ConnectionStream class today:
connFactory
is alazy val
, whileacquireConnection
andcreateConnectionChannel
aredef
s without parameters. This seems odd to me.def
s without parameters are equivalent toval
s when you do functional programming (cf. John de Goes), so why not make everything aval
and be more efficient?To me, this looks like the intention was to lazily initialize the
ConnectionFactory
exactly once when a connection is first acquired. But what this code actually does is create a newConnectionFactory
every time a connection is acquired. I would guess that that's not what the intention was, right? You can easily check this by e. g. adding some print statements inconnFactory
'sF.delay
block.I would like to point out that this issue is probably impossible to (correctly) fix this issue without changing the signature of
Fs2Rabbit.apply
. It currently returnsFs2Rabbit[F]
, but it will have to returnF[Fs2Rabbit[F]]
. This kind of initialization (whether lazy or non-lazy) ultimately requires some form of mutable state, and creating a mutable variable is in itself a side effect, as can be seen e. g. from the signature ofcats.effect.concurrent.Ref.of
, which returnsF[Ref[F, A]]
rather thanRef[F, A]
. So this is something that needs to be taken care of before the 1.0 release which I understand is imminent.The text was updated successfully, but these errors were encountered: