Skip to content
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

Specilized API for IO #7

Merged
merged 7 commits into from
Jul 3, 2024
Merged

Specilized API for IO #7

merged 7 commits into from
Jul 3, 2024

Conversation

jatcwang
Copy link
Contributor

@jatcwang jatcwang commented Jun 30, 2024

Closes #6

@jatcwang jatcwang mentioned this pull request Jun 30, 2024
@@ -20,7 +20,7 @@ import cats.implicits._
import munit.CatsEffectSuite

class CatchTest extends CatsEffectSuite {
val C = Catch.ioCatch.unsafeRunSync()
val C = Catch.catchForIO.unsafeRunSync()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed this to avoid confusion between ioCatch and ioCatching

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted as we're using IOCatch[E] now


object IOCatch {

def ioCatching[E]: IOCatchPartiallyApplied[E] =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively can be named catchingIO. Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an opinion on apply?

IOCatch[Error] { h =>
  // ...
}

Copy link
Contributor Author

@jatcwang jatcwang Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - that didn't cross my mind 😄 Done

for {
res <- ioCatching[String](h =>
IO.uncancelable(poll => poll(h.raise("oops")))
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is interesting because I couldn't get the RaisedInUncancellable exception to be thrown unless I remove the race in

F.race(prom.get, program).flatMap(_.fold(f, F.pure(_)))

Perhaps there's a race condition and somehow the outer cancellation always wins? 🤔
Either way, we will need to use raiseError to abort the execution anyway so nothing changes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just tried prom.get <* F.sleep(1.second) and it raised the error.

I think it is very hard to have it throw consistently without being able to query cats-effect about the "current cancelation" context.

Unfortunately I think that also means that the test "Can raise in an uncancellable region" might be flaky 😿

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can make both cases pass for now since it's race-y 🤷‍♂️ Will need to document this behaviour

@jatcwang
Copy link
Contributor Author

jatcwang commented Jul 2, 2024

Happy to add other missing test scenarios if you can think of anything else 🙂

Copy link
Owner

@ValdemarGr ValdemarGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some comments.

for {
res <- ioCatching[String](h =>
IO.uncancelable(poll => poll(h.raise("oops")))
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just tried prom.get <* F.sleep(1.second) and it raised the error.

I think it is very hard to have it throw consistently without being able to query cats-effect about the "current cancelation" context.

Unfortunately I think that also means that the test "Can raise in an uncancellable region" might be flaky 😿

@ValdemarGr
Copy link
Owner

Some of the Wall flags are complaining, LGTM otherwise

@ValdemarGr
Copy link
Owner

May I merge @jatcwang ?

@jatcwang
Copy link
Contributor Author

jatcwang commented Jul 3, 2024

Yes go for it thanks @ValdemarGr!

@ValdemarGr ValdemarGr merged commit 8cc63d7 into ValdemarGr:main Jul 3, 2024
4 checks passed
@jatcwang jatcwang deleted the io_catch branch July 3, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specialization for IO?
2 participants