-
Is this recommendation/guideline enough?
While creating a custom
To see what might be a good canonical way of creating a custom def unsafeCreateIORuntime(
computePoolThreadNamePrefix: String,
blockingECThreadNamePrefix: String,
schedulerThreadNamePrefix: String): IORuntime = {
lazy val global: IORuntime = {
val (compute, compDown) = createDefaultComputeThreadPool(global, computePoolThreadNamePrefix)
val (blocking, blockDown) = createDefaultBlockingExecutionContext(blockingECThreadNamePrefix)
val (scheduler, schedDown) = createDefaultScheduler(schedulerThreadNamePrefix)
IORuntime(
compute,
blocking,
scheduler,
() => {
compDown()
blockDown()
schedDown()
}
)
}
global
} This is a copy-paste of |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Great question! First off, the fact that The circumstances under which you want a custom
The two main reasons that it's possible to build custom The reason for this is simply that There's another scenario hinted at by the It's worth noting that the So to sum it all up: I don't think there are very many circumstances at all in which you would want a custom |
Beta Was this translation helpful? Give feedback.
-
To add to this, the |
Beta Was this translation helpful? Give feedback.
-
Thanks @djspiewak for the detailed answer. Glad that we can rely on Also checked out the accompanying issue #1238 and #1568. @vasilmkd Looking forward to the changes. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am looking for guidance on how to use IORuntime with Akka. Right now I am just needing it very minimally: I am using IO in the routes layer, to fetch data on a public key. As one uses cats-effect more, things will likely end up looking very different. At some point I may move to using cats effect without akka on the server (especially if there is a server using http3), and I am already using cats-effect with http4s on the client. I am writing libraries that can be used on the client and server (including node-js), which is why I have been looking to use the cats abstractions. Two good examples are bblfish/bobcats used by bblfish/httpSig, an implementation of "Signing Http Messages", which I would like to help being used as widely as possible, from client to server on any JS or Java platform. Perhaps this is a case where using |
Beta Was this translation helpful? Give feedback.
-
Thank you for the great discussion @ppurang and @djspiewak. I have a use case where I need to create my own runtime to limit the number of threads that will hit a third-party API since it has QPS limitations. Does this sound like a reasonable use of a custom runtime? Also, maybe this belongs to a different discussion but I'll throw it out there. What's is the expected behavior here: IO(...)
.evalOn(myExecutionContext)
.unsafeRunSync() // This requires the implicit IORuntime I understand that Thanks! |
Beta Was this translation helpful? Give feedback.
Great question!
First off, the fact that
IORuntime
doesn't allow the same constructor options externally as it has internally is (mostly) an oversight and should be fixed. The only exception to this is theWorkStealingPool
note, which I'm willing to hear counter-arguments on. Backing up…The circumstances under which you want a custom
IORuntime
are very niche. In fact, they're so niche that I almost want to just remove that guideline from the@implicitNotFound
text. It's easier to enumerate scenarios in which you don't want a custom runtime…IOApp
. The global pool is pretty much forcibly used withinIOApp
. We could probably adjust this, but I'm not sure I see a reason …