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

Skip to content

Conversation

@SHSongs
Copy link
Contributor

@SHSongs SHSongs commented May 2, 2023

Remove debug code from Ref-backed proxy class macro
#8061

@adamgfraser
Copy link
Contributor

@SHSongs Thanks for this! Noticed a couple of other things as I was working on using this to implement the reloadable functionality.

We want to be able to use the generate method in higher level code like this:

def reload[A: Tag]: IO[ServiceReloader.Error, Unit] =
  ??? // uses generate internally

Right now this doesn't work because for a polymorphic type "disallowed" methods such as getClass exist and it looks like even if this ignores there are other issues with the macro implementation.

Perhaps we could package this evidence up into a trait, say ReloadableService and automatically generate instances of that trait for any data type in which the constraints you implemented are satisfied?

@guersam
Copy link
Contributor

guersam commented May 3, 2023

Here's a quick sketch. Is this what you mentioned, @adamgfraser?

trait ReloadableService[A] {
  def tag: Tag[A]
  def serviceProxy: A // macro generated proxy
  def set[R, E](acquire: ZIO[R with Scope, E, A]): ZIO[R, E, Unit] // forward to underlying `ref: ScopedRef[A]`
}
// Use `ReloadableService[A]` instead of `Tag[A]`
def register[A: ReloadableService](serviceLayer: ZLayer[Any, Any, A]): IO[ServiceReloader.Error, A]

@adamgfraser
Copy link
Contributor

@guersam Yes I think so!

@SHSongs SHSongs marked this pull request as ready for review May 3, 2023 16:25
@jdegoes
Copy link
Member

jdegoes commented May 5, 2023

@guersam @SHSongs All revisions done & ready for review??

@guersam
Copy link
Contributor

guersam commented May 5, 2023

@jdegoes I think this one is done as it is, but the issue @adamgfraser pointed out should be addressed.

As the purpose #8061 was to support #8077, I'd like to ensure that the reworked macro works with ZLayer#reloadable.

Possible future actions:

  1. Open a new PR against zio/zio that depends on Implement ZLayer#reloadable #8077
  2. Open a new PR against adamgfraser/zio so that the new commits will eventually a part of Implement ZLayer#reloadable #8077

@jdegoes @adamgfraser Which way do you prefer?

@adamgfraser
Copy link
Contributor

@guersam I don't think we will be able to merge #8077 until the comment above is addressed because right now generate fails to compile when called from polymorphic code like ZLayer.reloadable. I think it is fine to make those changes here or we can merge this as is and you can open another PR depending on your preference. Thanks again for your work on this! 🙏

@guersam
Copy link
Contributor

guersam commented May 5, 2023

@adamgfraser Understood that option 1 is impossible. Then I'll make another PR against your fork (option 2) to discuss more design details in relation to ServiceReloader and to make sure the implementation meets the real requirement.

@adamgfraser
Copy link
Contributor

@guersam Sounds good!

@adamgfraser adamgfraser merged commit c32afc9 into zio:series/2.x May 5, 2023
@guersam
Copy link
Contributor

guersam commented May 5, 2023

Opened https://github.com/adamgfraser/zio/pull/12 for further discussion.

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.

4 participants