We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
cedeMap
intercede
Explicitly cede-ing between expensive compute-bound operations is one of the strategies for addressing CPU-starvation and is suggested in the warning.
cede
cats-effect/core/shared/src/main/scala/cats/effect/CpuStarvationCheck.scala
Lines 43 to 44 in 832079a
How to do this is described in the scaladocs for cede.
cats-effect/kernel/shared/src/main/scala/cats/effect/kernel/GenSpawn.scala
Lines 263 to 269 in 52b5a3b
Implementing that correctly is not completely trivial (*cough* #3166 😜) and noisy enough that it probably deserves its own combinator.
In fact I think we need a couple combinators, depending on whether or not the expensiveWork() is in F[_] or not.
expensiveWork()
F[_]
def cedeMap[A, B](fa: F[A])(f: A => B): F[B] = (fa <* cede).map(a => f(a)).guarantee(cede) def intercede[A](fa: F[A]): F[A] = cede *> fa.guarantee(cede)
(Names subject to bikeshed.) These should also be added as syntax and on IO itself.
IO
I think both variants are important, because for example the following would not achieve the desired semantics.
fa.flatMap(data => intercede(F.pure(expensiveWork(data))))
There, expensiveWork() would be computed eagerly when the pure(...) is constructed (before the cede), not when it is interpreted (after the cede).
pure(...)
The text was updated successfully, but these errors were encountered:
I want to help resolve this issue. 😃
Sorry, something went wrong.
@biuld go for it!
biuld
Successfully merging a pull request may close this issue.
Explicitly
cede
-ing between expensive compute-bound operations is one of the strategies for addressing CPU-starvation and is suggested in the warning.cats-effect/core/shared/src/main/scala/cats/effect/CpuStarvationCheck.scala
Lines 43 to 44 in 832079a
How to do this is described in the scaladocs for
cede
.cats-effect/kernel/shared/src/main/scala/cats/effect/kernel/GenSpawn.scala
Lines 263 to 269 in 52b5a3b
Implementing that correctly is not completely trivial (*cough* #3166 😜) and noisy enough that it probably deserves its own combinator.
In fact I think we need a couple combinators, depending on whether or not the
expensiveWork()
is inF[_]
or not.(Names subject to bikeshed.) These should also be added as syntax and on
IO
itself.I think both variants are important, because for example the following would not achieve the desired semantics.
There,
expensiveWork()
would be computed eagerly when thepure(...)
is constructed (before thecede
), not when it is interpreted (after thecede
).The text was updated successfully, but these errors were encountered: