Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

@adamgfraser adamgfraser commented Apr 25, 2023

/claim #8075

@adamgfraser adamgfraser requested a review from jdegoes April 25, 2023 15:46
@adamgfraser adamgfraser linked an issue Apr 26, 2023 that may be closed by this pull request
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for plugging in the real implementation and testing!

@adamgfraser
Copy link
Contributor Author

I think we have a problem here because we can't use macros in the same compilation unit they are defined in. But we want to use the macro in the implementation of ZLayer.reloadable in zio and the macro itself depends on ScopedRef in zio.

@adamgfraser
Copy link
Contributor Author

Also the Scala 3 macro implementation uses experimental features and so cannot be used from code that is not marked as experimental.

@adamgfraser
Copy link
Contributor Author

Okay this is ready to go. The last commit shows ServiceReloader is working but we need to move it out of ZIO Core so that it doesn't depend on a macro defined in the same compilation unit. Opened a PR to ZIO Config to do that. Once we merge this I can update that to depend on a snapshot version of ZIO and we can merge that in. I think there is a little more iterating we can do on naming but would like to do that afterwards.

@adamgfraser adamgfraser requested a review from jdegoes May 7, 2023 08:46
@jdegoes
Copy link
Member

jdegoes commented May 7, 2023

ZIO Config may be a really weird place to put this. Maybe we should introduce zio-macros here in core and we can have a one-import zio.macros._ that add all sort of extension methods that use macros, such as reloadable?

If ZIO comes to use macros more and more, this will be a common problem. And then ZIO Config can depend on zio-macros in order to add a hook that ties in reloading with config somehow.

What do you think?

@guersam
Copy link
Contributor

guersam commented May 7, 2023

An additional question, should we deprecate zio.Reloadable in favor of ZLayer#reloadable or does it have its own purpose?

@guersam
Copy link
Contributor

guersam commented May 7, 2023

Added a final touch to ServiceProxy to reflect its changed relationship with ServiceReloader. https://github.com/adamgfraser/zio/pull/13

@adamgfraser
Copy link
Contributor Author

adamgfraser commented May 7, 2023

@jdegoes I don't think we can do that because the macro needs to use ZIO data types, in particular ScopedRef. So reloadable can be somewhere other than ZIO Config but it needs to be something that is downstream of ZIO.

@jdegoes
Copy link
Member

jdegoes commented May 7, 2023

@adamgfraser Right, I imagined zio-macros being a new top-level project in this repository, which depends on core, and the user would add that project to their dependency.

@jdegoes
Copy link
Member

jdegoes commented May 7, 2023

@guersam

An additional question, should we deprecate zio.Reloadable in favor of ZLayer#reloadable or does it have its own purpose?

I think it could be considered deprecated after these changes because it forces you to go through get, which is not a pleasant user experience. However, for backward compat reasons we can't remove it anytime soon.

@adamgfraser
Copy link
Contributor Author

@jdegoes Yes we could do that. It is a bit odd because the functionality that it actually exposes would just be this reloadable operator but I guess you could think of it as "macro powered functionality provided by ZIO" so sure.

@jdegoes
Copy link
Member

jdegoes commented May 7, 2023

Yes we could do that. It is a bit odd because the functionality that it actually exposes would just be this reloadable operator but I guess you could think of it as "macro powered functionality provided by ZIO" so sure.

I can go either way. But I think if we're going to have more things like this, then it may make sense to have a project that contains them all, because that could improve discovery versus pushing "macro core" functionality into different projects across the ZIO ecosystem.

An example is RPC: it would be nice to have some functionality in ZIO that lets you easily do RPC with a ZIO service. It requires similar macros to here. It could be added as an extension method on ZLayer, e.g. ZLayer.gRPC[MyService].

@jdegoes
Copy link
Member

jdegoes commented May 7, 2023

@adamgfraser Take your pick on where to put that, I'm good either way.

@adamgfraser
Copy link
Contributor Author

👍

@guersam
Copy link
Contributor

guersam commented May 7, 2023

Maybe I missed the context, but doesn't zio-macros already exist in this repo?

@adamgfraser
Copy link
Contributor Author

@guersam It does. Right now it just contains the macros for generating service accessors. So it goes back to the idea that it becomes a little bit of a hodge hodge of somewhat unrelated functionality that is connected by the "how" versus the "what" but maybe that is the best we can do.

@adamgfraser
Copy link
Contributor Author

Anyway, will certainly make it easier to iterate on this if we are doing in one project.

jdegoes
jdegoes previously approved these changes May 7, 2023
@adamgfraser
Copy link
Contributor Author

I think this is ready to go now.

@adamgfraser adamgfraser requested a review from jdegoes May 7, 2023 18:00
@jdegoes jdegoes merged commit 388764d into zio:series/2.x May 7, 2023
@yarosman
Copy link

yarosman commented Jun 2, 2023

Does documentation exist about this new feature?

@adamgfraser
Copy link
Contributor Author

@khajavi Can you add?

@adamgfraser adamgfraser deleted the 8075 branch June 27, 2023 18:15
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

Successfully merging this pull request may close these issues.

Leverage proxy macro to build dynamically-reloadable services

4 participants