8000 `Runtime#unsafe.fork` doesn't fork synchronous effects · Issue #8751 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Runtime#unsafe.fork doesn't fork synchronous effects #8751
Closed
@kyri-petrou

Description

@kyri-petrou

Given the reproduction below, I'm expecting second to be printed first in the console. However, the following program blocks on the first effect, printing:

first
second
finished

I believe the issue is on this line, as start won't fork the effect until an async operation takes place. The call to start should be replaced with startConcurrently in order for the fiber to be forked immediately.

Note that runToFuture also uses start, and I think it should probably be changed

Repro

import zio.*

def fork(f: UIO[Unit]) = Unsafe.unsafely(Runtime.default.unsafe.fork(f))

val f1 = ZIO.succeed {
  Thread.sleep(1000)
  println("first")
}

val f2 = ZIO.succeed {
  println("second")
}

@main def run = {
  fork(f1)
  fork(f2)
  Thread.sleep(2000)
  println("finished")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0