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

Use JS macrotask executor for CE 2 #194

Merged
merged 2 commits into from
Mar 5, 2022
Merged

Use JS macrotask executor for CE 2 #194

merged 2 commits into from
Mar 5, 2022

Conversation

danicheg
Copy link
Member

@danicheg danicheg commented Mar 1, 2022

Even if we don't use fatal warnings, it, all the same, strikes the eye on every compile, CI run.

The global execution context in Scala.js is based on JS Promises (microtasks).
[warn] Using it may prevent macrotasks (I/O, timers, UI rendering) from running reliably.
[warn] 
[warn] Unfortunately, there is no way with ECMAScript only to implement a performant
[warn] macrotask execution context (and hence Scala.js core does not contain one).
[warn] 
[warn] We recommend you use: https://github.com/scala-js/scala-js-macrotask-executor
[warn] Please refer to the README.md of that project for more details regarding
[warn] microtask vs. macrotask execution contexts.
[warn] 
[warn] If you do not care about macrotask fairness, you can silence this warning by:
[warn] - Adding @nowarn("cat=other") (Scala >= 2.13.x only)
[warn] - Setting the -P:scalajs:nowarnGlobalExecutionContext compiler option
[warn] - Using scala.scalajs.concurrent.JSExecutionContext.queue
[warn]   (the implementation of ExecutionContext.global in Scala.js) directly.
[warn] 
[warn] If you do not care about performance, you can use
[warn] scala.scalajs.concurrent.QueueExecutionContext.timeouts().
[warn] It is based on setTimeout which makes it fair but slow (due to clamping)
[warn]                 
[warn]     IO.contextShift(ExecutionContext.global)

@armanbilge
Copy link
Member

Hmm, why not use the MacrotaskExecutor like the warning suggests?

@danicheg
Copy link
Member Author

danicheg commented Mar 1, 2022

@armanbilge because it brings new dependency and needs full-fledged testing. And yeah, I'm not an actual ScalaJS user.

@danicheg
Copy link
Member Author

danicheg commented Mar 1, 2022

Damn it, Scala 3 doesn't contain -P:scalajs:nowarnGlobalExecutionContext option :(

@armanbilge
Copy link
Member

FWIW the MacrotaskExecutor project was extracted from CE, is maintained by Daniel and I, and is the default in CE3.

@danicheg
Copy link
Member Author

danicheg commented Mar 5, 2022

@armanbilge so, I've followed your (and compiler's one) advice to use scala-js-macrotask-executor for CE2. If CE3 uses it as a default, I think it'd be fine for CE2 as well.

implicit def munitContextShift: ContextShift[IO] =
IO.contextShift(ExecutionContext.global)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use munitExecutionContext instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was intentional #65

Copy link
Member

Choose a reason for hiding this comment

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

Wow, munit uses parisitic EC ?? thanks for the pointer.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM 👍

@danicheg danicheg merged commit 0b75458 into main Mar 5, 2022
@danicheg danicheg deleted the js-warnings branch March 5, 2022 18:05
@danicheg danicheg changed the title Silence JS warnings for CE 2 Use JS macrotask executor for CE 2 Mar 5, 2022
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