Skip to content
New issue

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

Add Dispatcher[Task] instance #461

Open
renancaju opened this issue Nov 25, 2021 · 9 comments
Open

Add Dispatcher[Task] instance #461

renancaju opened this issue Nov 25, 2021 · 9 comments

Comments

@renancaju
Copy link

Method toManaged requires this instance but it does not exist.

@adamgfraser
Copy link
Contributor

Don't you actual want a dispatcher for F, the effect type you are converting from?

@joroKr21
Copy link
Contributor

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.

@renancaju
Copy link
Author

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?

@joroKr21
Copy link
Contributor

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

@renancaju
Copy link
Author

Cool.
Out of curiosity, why would we need toManaged for a generic F[_] in a ZIO Interop project?

@joroKr21
Copy link
Contributor

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.

@adamgfraser
Copy link
Contributor

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.

@joroKr21
Copy link
Contributor

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 🤔

@adamgfraser
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants