8000 Make some async api work on Scala.js and Native by lolgab · Pull Request #12 · com-lihaoyi/castor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make some async api work on Scala.js and Native #12

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

Merged
merged 4 commits into from
Sep 15, 2021
Merged

Make some async api work on Scala.js and Native #12

merged 4 commits into from
Sep 15, 2021

Conversation

lolgab
Copy link
Member
@lolgab lolgab commented Sep 14, 2021

This PR breaks binary compatibility in Scala.js and Scala Native but
doesn't touch binary compatibility for Scala JVM.
Since the methods removed weren't linking on JS/Native this can be
released as a patch release, until we find an API that works seamlessly in
all the platforms.
This deprecates Context.Impl.scheduler which cannot be implemented on
Native and JS and suggests to use scheduleMsg instead.

scheduleMsg is removed from Scala.js and Scala Native. We should probably
add an alternative using scala.concurrent.duration so it can be implemented in
all platforms, but since it wasn't working it is fine to remove for now since nobody
could use it either way.

./mill -i __.jvm.__.mimaReportBinaryIssues passes all binary compatibility checks

This PR breaks binary compatibility in Scala.js and Scala Native but
doesn't touch binary compatibility for Scala JVM.
Since the methods removed weren't linking on JS/Native this can be
released as a patch release, until we find an API that works seamlessly in
all the platforms.
This deprecates Context.Impl.scheduler which cannot be implemented on
Native and JS and suggests to use scheduleMsg instead.
@lolgab lolgab requested a review from lihaoyi September 14, 2021 11:06
@lihaoyi
Copy link
Member
lihaoyi commented Sep 15, 2021

@lolgab is it possible to duplicate less of the code? If the only thing that differs is scheduler/scheduleMsg, I'd only expect to see that logic changed between JVM/JS/Native and the rest of the boilerplate in Context.scala unchanged

@lolgab
Copy link
Member Author
lolgab commented Sep 15, 2021

It is possible if we change the API in a breaking way.
We need to either:

  • Change scheduleMsg signature from:
-def scheduleMsg[T](a: Actor[T],msg: T, delay: java.time.Duration)(implicit fileName: sourcecode.FileName, line: sourcecode.Line)
+def scheduleMsg[T](a: Actor[T],msg: T, delay: scala.concurrent.duration.FiniteDuration)(implicit fileName: sourcecode.FileName, line: sourcecode.Line)

Also I removed Context.Simple.threadPool, Context.makeThreadPool, Context.ThreadPool, Context.TestThreadPool from JS and Native and we need to find them another home if we want to duplicate less code.

My idea was to live with this for a bit until we find an API that works on all platforms that we are happy with and release a breaking version.

Let me know what approach you think is the best and I can try to implement it. :)

@lihaoyi
Copy link
Member
lihaoyi commented Sep 15, 2021 via email

@lolgab
Copy link
Member Author
lolgab commented Sep 15, 2021

Sadly you can't leave methods using java.time or java.util.concurrent in public traits without making the Scala.js linker complain ( Scala Native links just fine but it might be a bug ).
I tried another approach with mixins which is source compatible but not binary compatible ( it will require us to tag 0.2.0 ).
Please give a look and let me know what you think.

@lihaoyi
Copy link
Member
lihaoyi commented Sep 15, 2021

Looks good to me I think

This implements a different approach which is NOT binary
compatible, but is source compatible and avoid duplicating code.
The idea is to have mixins with different implementations
for every object or trait that has functions existing on JVM
only
@lolgab
Copy link
Member Author
lolgab commented Sep 15, 2021

@lihaoyi Ready for the final review.
Tests are green ✅.

@lihaoyi
Copy link
Member
lihaoyi commented Sep 15, 2021

Tagging 0.2.0 sounds good. Castor is still a relatively young library, so we should expect it to evolve over time where necessary.

Skimmed over the changes, looks good to me

@lolgab lolgab merged commit baf69d1 into com-lihaoyi:master Sep 15, 2021
@lolgab lolgab deleted the fix-async-native-js branch September 15, 2021 15:53
@lolgab lolgab restored the fix-async-native-js branch September 15, 2021 15:53
@lolgab lolgab deleted the fix-async-native-js branch September 15, 2021 15:53
@lolgab
Copy link
Member Author
lolgab commented Sep 15, 2021

0.2.0 was released. I also noticed there was already an issue open ( #7 ) which this PR fixed, so I closed it :)

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.

2 participants
0