-
Notifications
You must be signed in to change notification settings - Fork 357
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 WeakAsync.liftIO
#1910
Add WeakAsync.liftIO
#1910
Conversation
@armanbilge Thanks again for this. Could I beg a quick sanity check from you please? My placeholder for this was:
and now I have:
I think this is basically equivalent right? And I'm unsafeRunSync'ing because the whole point of lifting this, for me, is to roll an IO result into a CIO for comprehension |
This example, above, doesn't actually appear to work 😂 👀 |
@henricook I'm not sure why it's not working, but there's a lot of non-idiomatic things happening there. Can you build the object App extends IOApp.Simple {
def run = WeakAsync.liftIO[ConnectionIO].use { implicit lifter =>
// ...
ioB.to[ConnectionIO] // this is a method on IO, you don't need your own syntax
// ...
}
} |
Wow that's one of those things where I was totally blind to it until you said that, and definitely shouldn't have been. On the whole putting this in my IOApp and passing it around implicitly works. One area where I have trouble is in my effectful logging wrapper: trait Logging {
lazy val dbLogger: MyLogger[ConnectionIO] = loggerF[ConnectionIO]
private lazy val _logger: Logger = LoggerFactory.getLogger(getClass.getName) // slf4j
@nowarn def loggerF[F[_]: LiftIO: Sync: Functor]: MyLogger[F] = MyLogger(_logger)
} Because this trait's just mixed in anywhere I need logging, I don't think that I have a way to pass in the LiftIO injected by IOApp. Without passing it to almost every service/controller/connector in the app anyway. So that's my only remaining thinker 🤔 . I appreciate that one's very much a my app problem and no longer a general usability problem. Thanks for the education above ^! |
Why does a Logger need to lift IO to CIO? Because at some points it reads 'Audit Context' (request ids etc.) to include in the log entries from an IOLocal - which is another topic I know you love to discuss :-D |
Even with everything wired up to use the IOApp injected resource (excluding the Logger which i've just no-op'd for now):
Despite compiling fine, it's like the action never gets evaluated so acceptance tests that do these actions aren't seeing the expected results. Items of potential interest, I'm in a Play Application so building an ApplicationModule with an ApplicationLoader, like this:
In the I deal with |
Sorry, I'm not sure why it's not working for you 😕 if you can get it down to a runnable example I can take a look. |
FWIW I could not recreate the issue with:
Prints:
|
Oh but here we are, changing that run line to:
Published here: https://github.com/henricook/doobie-liftio-repro1123/blob/main/src/main/scala/com/example/Main.scala It could just be that I've done something foolish in the quick project setup |
@henricook I believe that should be |
Right you are, curses! I think I've taken up enough of your time and my old bodge is holding, so I'll try to ignore the problem until one day inspiration strikes. Thanks again for your work and help here. |
Ah, the problem was not my implementation of lifting but the fact that this lift method nukes IOLocal (with your cats effect branch's unsafe changes in effect Arman) and my original did not. Probably I guess (total guess tbh) because of the boundary created through the use of a Dispatcher? More background: Lots of my code that actions changes also must audit changes for them to succeed. Audit was failing because the |
Ah yes, we discussed this. I don't have a good idea yet for how to get |
So that we can specifically get a
LiftIO
. h/t @henricook for the idea.