Skip to content

Conversation

@alstepan
Copy link

An implementation for #4409

@durban
Copy link
Contributor

durban commented Nov 23, 2025

Thanks for the PR. I'm wondering, what is the intention here? To print which thread exactly?

@asarkar
Copy link

asarkar commented Dec 15, 2025

@durban Not sure I understand your question, Thread.currentThread returns the currently executing thread, no?

@durban
Copy link
Contributor

durban commented Dec 15, 2025

Sure, but which thread, executing what code, when? The thread writing to stdout? The thread executing this: IO[A]? The thread executing the closure in the guaranteeCase? (Again, I'm asking for the intention here.)

@asarkar
Copy link

asarkar commented Dec 16, 2025

The thread in guaranteeCase as shown in the ticket.

@asarkar
Copy link

asarkar commented Dec 16, 2025

The intent is to add thread name to prefix wherever it appears.

Copy link
Member

@djspiewak djspiewak left a comment

Choose a reason for hiding this comment

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

So asking @durban's question a slightly different way, it's not clear why you need the name of the carrier thread. Can you explain the use-case a bit more here? What are you trying to determine by printing this out? I genuinely have no objections to it (once the implementation is fixed), but I don't really get what you're trying to accomplish.

Cats Effect moves fibers freely between carrier threads depending on a whole host of very complex factors. In non-degenerate cases, it shouldn't matter what the underlying thread is. I definitely get that, particularly with custom thread pools, you may have a scenario where this is required, but I'd like to understand that better.

case Outcome.Succeeded(ioa) =>
ioa.flatMap(a => IO.println(s"${prefix}: Succeeded: ${S.show(a)}"))
ioa.flatMap(a =>
IO.println(s"[${Thread.currentThread().getName}] ${prefix}: Succeeded: ${S.show(a)}"))
Copy link
Member

Choose a reason for hiding this comment

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

Thread.currentThread() is a side effect and should be wrapped in IO. The reason for this becomes much more apparent when you look at the output for the Canceled case in particular, which will frequently be inconsistent with the thread on which the IO is actually executing!

Copy link

Choose a reason for hiding this comment

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

It’d be helpful for the same reason prefix exists, debugging.

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