-
Notifications
You must be signed in to change notification settings - Fork 7
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
Make a macrotask-executor shim on the jvm side #39
Comments
Workaround by using platform-specific imports: // js
import org.scalajs.macrotaskexecutor.MacrotaskExecutor
import scala.concurrent.ExecutionContext
trait MacroExecutorImpl {
def globalImpl: ExecutionContext = MacrotaskExecutor.Implicits.global
}
// jvm
import scala.concurrent.ExecutionContext
trait MacroExecutorImpl {
def globalImpl: ExecutionContext = ExecutionContext.global
}
// shared
object MacroExecutor extends MacroExecutorImpl {
implicit def global: ExecutionContext = globalImpl
}
// shared use
import path.to.your.MacroExecutor._ |
Thanks for reporting! Having cross-compiled lots of libraries for JVM/JS I completely understand the nuisance this creates. However, shimming the A slight rephrasing of this issue could be:
The explanation for why the |
Thanks for the explanation! When coding shared code though, one needs to have both implementations anyway somehow and it would be nice without workarounds. Maybe the subject of micro/macrotasks are not that important from the user perspective and more of an implementation consideration? Would the weird/confusing thing of a shared api be that |
💯 agree. I think in an ideal world this would live in However, it is almost definitely out-of-scope for this project to do that. For example, what if someone opens an issue asking us to also shim this for Scala Native? Should we do that too, why/why not? |
Scala Native is a good point. Perhaps this is a job for https://github.com/portable-scala, actually. |
Exactly my thinking! :) |
How many shims are we potentially talking about? |
My side on this is that importing a specific Example: // shared code
class MyService(implicit ec: ExecutionContext) {...}
// js
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
class JsMain {
val service = new MyService
}
// jvm
import scala.concurrent.ExecutionContext.Implicits.global
class JvmMain {
val service = new MyService
} |
Crosscompiling the macrotask-executor to both js/jvm would allow to use it in shared code without having to make platform-specific imports. Possibly by using a standard/supplied ExecutionContext shim on the jvm side.
The text was updated successfully, but these errors were encountered: