chepiov / cats-effect-miscellaneous Goto Github PK
View Code? Open in Web Editor NEWSome exercises and examples of Cats Effect
Some exercises and examples of Cats Effect
I like your implementation with versions, however, exec
not safe wrt cancellation:
for {
(workerVersion, worker) <- current.take
// [X]
currentVersion <- version.get
// [Y]
b <- if (currentVersion == workerVersion)
worker(a).guarantee(back(workerVersion, worker))
else exec(a)
} yield b
Because of cancelable flatMaps, it's possible for cancellation to happen at [X]
or [Y]
, in which case you leak the worker (as it's never returned to the MVar, even if I didn't do removeAll
).
You can fix it using uncancelable
, but you don't want to make everything uncancelable. bracket
would work too (acquire and release parts of bracket are uncancelable), but looping and de-structuring would be painful.
It seems (from the code) that you're building a tree of CompositeExceptions with prepend
, i.e.
CompositeException(
throwable1,
CompositeException(
throwable2,
CompositeException(
...
)
)
)
It also seems that your getMessage
override would not discriminate between these cases :) Ideally, you'd want to somehow ensure you work with CompositeException
instead of Throwable
, which you can safely combine together.
Custom extractors are a nice touch, but there's also an option to avoid matching on two cases: Either has merge
method, which can only be called if left and right have (potential) same type. So, you can do something like either.leftMap(_.swap).merge
to get (Fiber[...], Either[...])
.
And if it all seems like nitpicking, that's because there's not really anything significant for me to complain about. Nice solutions, and congratulations ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.