Open domdorn opened 3 years ago
Any Ammonite users who can comment on this? I have a hard time believing ZIO just doesn't work on Ammonite, in fact I know it does because we have special support for it in ZIO Test, but doesn't use it personally.
I just got feedback in the ammonite-gitter. When putting the unsafeRun call into a main method, it starts to work
val program = ....
@main
def main( path: os.Path = os.pwd) = {
println("should run program now")
println(program)
println()
zio.Runtime.default.unsafeRun(program.provideLayer(zio.ZEnv.live)) // here it just blocks and does nothing!
println("should have run program now")
}
maybe we can put this into the docs somewhere?
It would be good to coordinate with Li to see if there is some way we can work around behavior. Technically this isn't a bug in ZIO, but Ammonite is a very important tool to work smoothly with.
so, I have a new insight: it looks like everything that is trying to spawn a thread outside the scope of a @main def xxx()
method is blocking the whole thing, e.g. even using the parallel collections of scala. I guess it might have something todo with that the code outside a @main
annotated method would be basically the static initializer of a class? not sure, but this is what I observed
Yes it seems like this really needs to be handled on the Ammonite end.
I'm pretty sure the is related to https://github.com/com-lihaoyi/Ammonite/issues/534 which is closed by shouldn't be. I've run into it a lot. eg this fails
val f = Future {
println("a")
}
Await.result(f, 1 second)
but if you wrap it in an object or main
function it is ok.
So:
@main
def main() = {
...
}
After thinking about it, running an effect outside the @main basically is the same as in this screenshot
Maybe we can find a way to make a suitable error message or something
script.sc
execute
expected behavior
program runs the effect
actual behavior
program runs till the unsafeRun, then just hangs without executing the effect
aditional info