Comments (2)
@edio good question. What is best practice
escapes me at the moment, need to do a little more research on that end.
As to why things are the way they are, I can give a little color on that.
Originally, I believe everything in the for comprehension was loaded in IO
. The motivation being that if anything failed when the app started up, the app wouldn't start up.
Now, the Server
itself has gone through revisions as dependent libraries have been updated. Most likely (without looking at the commit history), Resource
was introduced as part of the update to http4s 0.20. You can see the example on starting an Http4s service uses Resource
similar to what we have - https://http4s.org/v0.20/service/
Also, doobie also leverages Resource
. Both of those make sense, because not only do you want to acquire a resource, you also want to control the finalizer (which seems reasonable for an HTTP Server and a database).
For the things that "aren't really Resource" in that for comprehension, the release does nothing. From what I have gathered Resource
is just an ADT with a finalizer
, and for many circumstances (using liftF
) you have no finalizer.
For example, the line Resource.liftF(parser.decodePathF[F, PetStoreConfig]("petstore"))
is doing nothing more than eventually running the expression inside the Resource
, just like IO
, and when it is complete essentially it will not do anything.
When building a for comprehension, we have to lift all the things into a common Monad, so here the "unwavering" Monad is Resource
I will ping some folks around here to see if this is considered idiomatic, and if there are any downsides
from scala-pet-store.
I think Paul covered this pretty well. Resource.liftF
and Resource.pure
just put values into the Resource context with no extra machinery. The final call in Server kicks the server off and never returns. So there should not be a difference between using the underlying values directly, or using the values within the Resource context. Neither will fall out of scope.
And yeah to echo Paul's point, circe-config
just hands off to typelevel's config for opening and closing the file, and returning the case class instances inside of some F
. So that part is interesting, if the F is IO, then I would expect within that IO, the file is opened, parsed, and closed, before the next line in the for
expression is executed.
This question helped us think about these issues a bunch, so thanks. I'm going to go ahead and close this and feel free to reopen the discussion in the gitter channel.
from scala-pet-store.
Related Issues (20)
- Use `requests.request(params=xxx)` for python client
- Add scala-steward to project HOT 6
- Switch to circe-config HOT 5
- Travis is not connected HOT 4
- Dockerize sbt build
- Add github pages deployment to travis HOT 2
- add Scala 2.13 crossbuild HOT 3
- Application gets blocked on db connection acquisition if more than 10 concurrent clients connect HOT 3
- Implement Tracing and Stats
- n HOT 3
- Having problem with sbt compile HOT 3
- Thanks note and request for an note HOT 1
- Change Python version in README HOT 1
- Scalacheck spots error in PetEndpoints HOT 1
- Pet and Order status can get out of sync
- Have you considered the library freestyle?
- SQLPagination drops SQL parameters HOT 1
- Scala 2.13.6 Unused Parameter Value for Higher Kinded Type HOT 1
- Remove monad transformer return types from algebras HOT 1
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 scala-pet-store.