typelevel / cats-effect

The pure asynchronous runtime for Scala
https://typelevel.org/cats-effect/
Apache License 2.0
2.03k stars 520 forks source link

`Dispatcher`: avoid spinning #4052

Closed durban closed 5 months ago

durban commented 7 months ago

This is a small internal refactoring of the "new" Dispatcher.

Currently during cancellation there is a racy write/read of action (a plain var), and this is resolved by spinning on stateR (an AtomicReference). The idea of this PR is that since we already have an AtomicReference, which we're reading anyway, we can avoid the data race, and thus the spinning, by putting action inside the AtomicReference.

Besides this, there are 2 very small changes: removing an outdated comment, and an unnecessary type parameter.