typelevel / munit-cats-effect

Integration library for MUnit & cats-effect
Apache License 2.0
148 stars 34 forks source link

Use JS macrotask executor for CE 2 #194

Closed danicheg closed 2 years ago

danicheg commented 2 years ago

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 commented 2 years ago

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

danicheg commented 2 years ago

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

danicheg commented 2 years ago

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

armanbilge commented 2 years ago

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

danicheg commented 2 years ago

@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.