Comments (5)
Hi @mberndt123 ,
Thanks for raising your concerns here. You are right about that lazy val
and def
, they can be made a val
since they are referentially transparent (sending in a PR as I reply).
However, your other assumptions are wrong, let me explain why.
You can easily check this by e. g. adding some print statements in connFactory's F.delay block.
Have you tried doing this? It doesn't happen because the functions are RT.
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 returns Fs2Rabbit[F], but it will have to return F[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 of cats.effect.concurrent.Ref.of, which returns F[Ref[F, A]] rather than Ref[F, A]. So this is something that needs to be taken care of before the 1.0 release which I understand is imminent.
F[Fs2Rabbit[F]]
used to be the shape of the creation but it has changed since 1.0-RC2
(see #105) because the creation of Fs2Rabbit[F]
is no longer effectful as it used to be. The only effect that happened before was the creation of the internal fs2 Queue to interact with the Java consumers and publishers but that is now in a different interpreter.
You can try creating as many interpreters of Fs2abbit[F]
as you want and introduce a println
in connFactory
if you want to be sure that nothing is happening.
from fs2-rabbit.
Hi @gvolpe, thanks for responding. However I don't believe this is fixed.
Have you tried doing this? It doesn't happen because the functions are RT.
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 println("making ConnectionFactory")
statement just before the new ConnectionFactory()
line inside the F.delay
block in connFactory
. And I see the "making ConnectionFactory" line twice when running the test. Is that really the intended behaviour? Because I don't see the point in creating two connection factories.
from fs2-rabbit.
Well, you are calling acquireConnection
twice so the effect runs... twice as one would expect.
Anyway the acquireConnection
method is private[fs2rabbit]
(not exposed to the users of the library) so I believe you are just writing a test in the library itself?
Users shouldn't be creating a ConnectionStream
themselves but if they do then they should know what they are doing there.
The library only exposes the createConnectionChannel
which (as you might have guessed) creates a new connection and channel every time is invoked.
Does that answer your question?
from fs2-rabbit.
Well, you are calling
acquireConnection
twice so the effect runs... twice as one would expect.
Sure, I do expect two connections to be acquired. However that doesn't require creating two different ConnectionFactory
objects, yet this is what the code does.
Anyway the acquireConnection method is private[fs2rabbit](not exposed to the users of the library) so I believe you are just writing a test in the library itself?
Well, that was for simplicity, but as a user I could also do s.createConnectionChannel.repeat.take(2)
. I wouldn't expect two ConnectionFactory objects to be created in this case.
The library only exposes the createConnectionChannel which (as you might have guessed) creates a new connection and channel every time is invoked.
Right, but it also create a new ConnectionFactory
every time, and I would argue that's unnecessary.
from fs2-rabbit.
Right, but it also create a new ConnectionFactory every time, and I would argue that's unnecessary.
Oh that's what you really meant. Sure, I think you're right here. Looking more into ConnectionFactory
itself it seems a bit side-effecty so I might change the way a connection is being acquire now to make sure only one instance of ConnectionFactory
is created. Thanks! :)
from fs2-rabbit.
Related Issues (20)
- Microsite is not available HOT 2
- Allow configuring the ConnectionResource ThreadFactory HOT 2
- Unsafe creation of consumers HOT 2
- Looking for new maintainers! HOT 10
- Update to cats-effect 3.x ecosystem HOT 4
- Allow "multiple" ack flag to be reset per call HOT 2
- Durations in Fs2RabbitConfig HOT 1
- 'Config' part of guide website has a different example from what is on github HOT 1
- plugin support rabbitmq-delayed-message-exchange HOT 3
- Unexpected message order in consumer HOT 2
- Configurable shared executor service for com.rabbitmq.client.impl.ConsumerWorkService HOT 1
- Feature : Client-Provided Connection Name HOT 4
- Doc site examples are for cats-effect 2 HOT 2
- Invalid code example on the site (despite mdoc) HOT 1
- Stream stucks if the server closes the channel
- Expired gpg key HOT 6
- Allow "requeue" nack flag to be reset per call HOT 1
- Can't create a publisher to publish directly to a queue? HOT 2
- How is ResilientStream supposed to work in the context of RMQ? HOT 2
- Can't find release 5.1.1 in maven repositories HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fs2-rabbit.