interop-cats
interop-cats copied to clipboard
Add Dispatcher[Task] instance
Method toManaged
requires this instance but it does not exist.
Don't you actual want a dispatcher for F
, the effect type you are converting from?
Just to clarify - Dispatcher
is not a type class so we can't have a generic instance. Creating a dispatcher returns a Resource
which needs to be cleaned up after you're done using it. I struggled a lot with trying to make Dispatcher
usage more ergonomic but I didn't come up with anything. There is definitely room for improvement here.
Fiddling around, I think I might have mixed up the uses of toManaged
and toManagedZIO
which does not need a Dispatcher
. Am I right? In order to convert a cats Resource
to a ZManaged
can I just use toManagedZIO
instead?
Fiddling around, I think I might have mixed up the uses of toManaged and toManagedZIO which does not need a Dispatcher. Am I right? In order to convert a cats Resource to a ZManaged can I just use toManagedZIO instead?
Yes, that's why it exists. When the F[_]
in Resource
is itself ZIO
we don't need Dispatcher
and that makes it much easier to use. 👍
Cool.
Out of curiosity, why would we need toManaged
for a generic F[_]
in a ZIO Interop project?
I think for the people that mix ZIO with other effect types. Maybe we should have used the short name for ZIO and a longer name for generic effects 🤔 - but I think it's too late to change now.
Yeah I would actually think the toManaged
variant would be more common where you had like a Resource[CIO, A]
and wanted to convert it into a ZManaged
. And that is where you would need a Dispatcher[CIO]
which would need to come from Cats and not from ZIO.
Yeah I would actually think the toManaged variant would be more common where you had like a Resource[CIO, A] and wanted to convert it into a ZManaged.
If you use only ZIO and tagless final libraries like http4s and doobie then you don't actually have this problem.
And that is where you would need a Dispatcher[CIO] which would need to come from Cats and not from ZIO.
Yeah, the issue is that the Dispatcher
constructor gives you a Resource
- so catch 22 🤔
Yes we definitely want to support both styles.
If you are working with Dispatcher
and your application isn't ultimately a Cats Effect application then you are going to have to unsafely run creating a dispatcher somewhere to use in nested scopes.