Skip to content
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

An exploration of cats.mtl.Stateful tracing #103

Closed
wants to merge 2 commits into from
Closed

Conversation

rossabaker
Copy link
Member

Like #102, but Stateful instead of Local.

Comment on lines +52 to +62
def stateful[S](a: S): IO[Stateful[IO, S]] =
IOLocal(a).map { ioLocal =>
new Stateful[IO, S] {
override def get: IO[S] =
ioLocal.get
override def set(s: S): IO[Unit] =
ioLocal.set(s)
override def monad: Monad[IO] =
Monad[IO]
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if this is lawful.

@@ -47,67 +47,68 @@ private[java] object TraceScope {
case object Noop extends Scope
}

def fromIOLocal[F[_]: LiftIO: Sync](
private[java] def fromStateful[F[_]: Sync: Stateful[*[_], Scope]](
Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike Local, it's not as obvious what other instances we're bringing to the table here. StateT over a Concurrent is generally a bad idea. StateT over a MonadError can go up in smoke.

Could something clever be done with a Ref?

Can we interoperate with synchronous Java with a gulp ThreadLocal? Uh... probably not, because we also need a Sync?

Comment on lines +86 to +87
Stateful[F, Scope].get.flatMap(p =>
Stateful[F, Scope].set(scope).as(p)
Copy link
Member Author

Choose a reason for hiding this comment

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

Does this need to be atomic? 🤔

@rossabaker
Copy link
Member Author

I don't think this is going to work without solving the fs2 interruptScope issue, which I don't think is going to work without solving the CE race local state reconciliation issue, which I don't think is going to be solved.

@rossabaker rossabaker closed this Jan 30, 2023
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.

1 participant