{"action":"created","issue":{"url":"https://api.github.com/repos/scalaz/ioeffect/issues/29","repository_url":"https://api.github.com/repos/scalaz/ioeffect","labels_url":"https://api.github.com/repos/scalaz/ioeffect/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/scalaz/ioeffect/issues/29/comments","events_url":"https://api.github.com/repos/scalaz/ioeffect/issues/29/events","html_url":"https://github.com/scalaz/ioeffect/issues/29","id":319758580,"number":29,"title":"Help me understand racing :)","user":{"login":"NeQuissimus","id":628342,"avatar_url":"https://avatars0.githubusercontent.com/u/628342?v=4","gravatar_id":"","url":"https://api.github.com/users/NeQuissimus","html_url":"https://github.com/NeQuissimus","followers_url":"https://api.github.com/users/NeQuissimus/followers","following_url":"https://api.github.com/users/NeQuissimus/following{/other_user}","gists_url":"https://api.github.com/users/NeQuissimus/gists{/gist_id}","starred_url":"https://api.github.com/users/NeQuissimus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NeQuissimus/subscriptions","organizations_url":"https://api.github.com/users/NeQuissimus/orgs","repos_url":"https://api.github.com/users/NeQuissimus/repos","events_url":"https://api.github.com/users/NeQuissimus/events{/privacy}","received_events_url":"https://api.github.com/users/NeQuissimus/received_events","type":"User","site_admin":false},"labels":[{"id":897204956,"url":"https://api.github.com/repos/scalaz/ioeffect/labels/question","name":"question","color":"d876e3","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-03T00:54:58Z","updated_at":"2018-05-03T01:31:13Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"OK, so here I thought race was straight-forward. Clearly I am doing something wrong...\r\n\r\n```scala\r\nimport $ivy.`org.scalaz::scalaz-ioeffect:2.1.0`, scalaz._, ioeffect._, Scalaz._, scala.concurrent.duration._\r\n\r\nobject App extends SafeApp {\r\n    type Error = Exception\r\n  \r\n    def run(args: List[String]): IO[Error, Unit] = {\r\n      val io1 = IO.sleep[Error](10.seconds).fork[Error]\r\n      val io2 = IO.point[Error, Unit]{ println(\"Hello\"); Thread.sleep(500L) }.forever[Unit].fork[Error]\r\n      io1.race(io2).toUnit\r\n}\r\n\r\nApp.main(Array.empty)\r\n```\r\n\r\nI was under the impression the two `IO` would race each other and once the first one finishes (clearly the sleeper, since the other one is a `forever` guy), the slower one is interrupted and will never be heard of again.\r\nIn the above code `io2` is completely unfazed by the race and will keep on running forever. Can an `IO.forever` not be interrupted?\r\n\r\nAnyways, I changed things around a bit, thinking maybe one of the fibres is not allowed to be forked, and now I have this:\r\n\r\n```scala\r\nimport $ivy.`org.scalaz::scalaz-ioeffect:2.1.0`, scalaz._, ioeffect._, Scalaz._, scala.concurrent.duration._\r\n\r\nobject App extends SafeApp {\r\n  type Error = Exception\r\n\r\n  def run(args: List[String]): IO[Error, Unit] = {\r\n    val io1: IO[Error, Unit] = IO.sleep[Error](10.seconds).fork[Error].toUnit\r\n    val io2: IO[Error, Unit] = IO.point(println(\"Hello\")).forever[Unit]\r\n    io1.race(io2)\r\n  }\r\n}\r\n\r\nApp.main(Array.empty)\r\n```\r\n\r\na) The race lasts maybe 1 second, not 10, not forever\r\nb) Sometimes I get a bunch of prints but usually only one\r\n\r\n---\r\n\r\nHere is essentially what I need (maybe there is a significantly better way to do this):\r\n\r\n- I have two `IO[Error, Unit]` (let's call them `X` and `Y`)\r\n- `X` runs forever (it's a streaming processor)\r\n- `Y` does a bunch of stuff, then completes\r\n- I need `X` to start, then `Y` to start. Once `Y` has completed, interrupt `X`, collect results, done"},"comment":{"url":"https://api.github.com/repos/scalaz/ioeffect/issues/comments/386169425","html_url":"https://github.com/scalaz/ioeffect/issues/29#issuecomment-386169425","issue_url":"https://api.github.com/repos/scalaz/ioeffect/issues/29","id":386169425,"user":{"login":"ktonga","id":1324947,"avatar_url":"https://avatars1.githubusercontent.com/u/1324947?v=4","gravatar_id":"","url":"https://api.github.com/users/ktonga","html_url":"https://github.com/ktonga","followers_url":"https://api.github.com/users/ktonga/followers","following_url":"https://api.github.com/users/ktonga/following{/other_user}","gists_url":"https://api.github.com/users/ktonga/gists{/gist_id}","starred_url":"https://api.github.com/users/ktonga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktonga/subscriptions","organizations_url":"https://api.github.com/users/ktonga/orgs","repos_url":"https://api.github.com/users/ktonga/repos","events_url":"https://api.github.com/users/ktonga/events{/privacy}","received_events_url":"https://api.github.com/users/ktonga/received_events","type":"User","site_admin":false},"created_at":"2018-05-03T01:31:13Z","updated_at":"2018-05-03T01:31:13Z","author_association":"NONE","body":"Maybe in this very case it is not the reason, but in general i'd not recommend to try concurrent-ish stuff on the REPL, I see you are using Ammonite, dunno  if it is the same as with `sbt console` but I always get better (expected) behavior when writing a little app in a scala file and using `sbt run`"}}
{"actor":{"display_login":"ktonga"}}