Spot the bug in the eager Future wrapper

from Scala backend development
Scala 3.9.0 / Cats Effect 3.7.1 / http4s 0.23.36 / Java 25 LTS advanced 4 min 1 issue to find

Why can this repository call begin before the returned `IO` is run?

scala
def load(id: Long)(using ec: ExecutionContext): IO[User] = {
  val started = Future(repository.find(id))
  IO.fromFuture(IO.pure(started))
}
Open in playground
Report an error