Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,14 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
implicit S: Show[B] = Show.fromToString[B]): IO[A] =
guaranteeCase {
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.


case Outcome.Errored(ex) =>
IO.println(s"${prefix}: Errored: ${ex}")
IO.println(s"[${Thread.currentThread().getName}] ${prefix}: Errored: ${ex}")

case Outcome.Canceled() =>
IO.println(s"${prefix}: Canceled")
IO.println(s"[${Thread.currentThread().getName}] ${prefix}: Canceled")
}

/**
Expand Down
Loading