Skip to content

blocking and interruptible on Scala Native #4378

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

Open
wants to merge 4 commits into
base: series/3.x
Choose a base branch
from

Conversation

djspiewak
Copy link
Member

Fixes #4331
Fixes #4374
Closes #4360

This ports interruptible and blocking to the shared JVM/Native cross-build structure. I had to split apart IOCompanion a bit more since the CompletableFuture stuff is still JVM-only. Is that implemented on SN now? I'm assuming not. The other weird caveat came from the special ClosedByInterruptException semantics on JVM and its nonexistence on Native.

@djspiewak djspiewak added this to the v3.7.0 milestone Apr 14, 2025
@djspiewak
Copy link
Member Author

Also fixes #4323

@djspiewak djspiewak linked an issue Apr 14, 2025 that may be closed by this pull request
@armanbilge
Copy link
Member

armanbilge commented Apr 14, 2025

bit more since the CompletableFuture stuff is still JVM-only. Is that implemented on SN now? I'm assuming not.

It is!

https://github.com/scala-native/scala-native/blob/f2964e8d459b571641d5cd9c9da58d41df461c2e/javalib/src/main/scala/java/util/concurrent/CompletableFuture.scala

Edit: caveat, it landed in SN 0.5.7, which we are struggling to upgrade to.

private[effect] object InterruptThrowable {
def apply(t: Throwable): Boolean = t match {
case _: InterruptedException => true
case _: ClosedByInterruptException => true
Copy link
Member

Choose a reason for hiding this comment

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

ClosedByInterruptException also landed in SN 0.5.7.

Copy link
Member Author

Choose a reason for hiding this comment

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

Le sigh… Well, we'll remove my shims when we do.

Comment on lines +171 to +179
ticked("realTimeInstant should return an Instant constructed from realTime") {
implicit ticker =>
val op = for {
now <- IO.realTimeInstant
realTime <- IO.realTime
} yield now.toEpochMilli == realTime.toMillis

assertCompleteAs(op, true)
}
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the duplicate test from the Native-specific test suite:

ticked("realTimeInstant should return an Instant constructed from realTime") {
implicit ticker =>
val op = for {
now <- IO.realTimeInstant
realTime <- IO.realTime
} yield now.toEpochMilli == realTime.toMillis
assertCompleteAs(op, true)
}

Comment on lines -68 to +67
case ex: ClosedByInterruptException => throw ex
case t if InterruptThrowable(t) => throw t
Copy link
Member

Choose a reason for hiding this comment

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

Was the lack of InterruptedException here an oversight? Otherwise it seems like this is changing the semantic 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

It's incorporated in the matcher

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I think that was unclear: the previous matcher checked only for ClosedByInterruptException, but the new matcher now checks for both ClosedByInterruptException and InterruptedException. That's the change in semantic I'm referring to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants