Last active
February 3, 2026 20:21
-
-
Save dacr/1edeb107fb650d1558095c4984e490c2 to your computer and use it in GitHub Desktop.
zio-streams ZStream collectZIO stucked forever #7301 ? / published by https://github.com/dacr/code-examples-manager #84637c86-ace7-4483-907c-c59cffd2d616/e5a489496bbd1a79a418807ba2fc98b8dc958b41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : zio-streams ZStream collectZIO stucked forever #7301 ? | |
| // keywords : scala, ziostream, issue | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 84637c86-ace7-4483-907c-c59cffd2d616 | |
| // created-on : 2022-09-03T09:32:10+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // attached-files | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.4.2" | |
| //> using dep "dev.zio::zio-streams:2.0.10" | |
| // --------------------- | |
| // https://github.com/zio/zio/issues/7301 | |
| import zio.* | |
| import zio.stream.* | |
| import scala.util.matching.Regex | |
| import java.time.LocalDateTime | |
| import java.time.format.DateTimeFormatter | |
| object Photos extends ZIOAppDefault { | |
| def parseTimestamp(timestamp: String): ZIO[Any, Throwable, LocalDateTime] = ZIO.succeed(LocalDateTime.now()) | |
| def run = for { | |
| _ <- ZIO.log(s"scanning...") | |
| mask <- ZIO.attempt(""".*/(\d{8}-\d{6})-\d{2}-(.*)-evt.jpg""".r) | |
| entries <- | |
| ZStream | |
| .fromIterable(List("./20220902-162930-00-raspcam1-evt.jpg", "./20220901-195134-00-raspcam1-evt.jpg", "./20220901-204013-00-raspcam1-evt.jpg")) | |
| .filterNot(_.contains("Trash")) | |
| .collectZIO { case file @ mask(timestamp, group) => parseTimestamp(timestamp).map(ts => ts -> file) } // https://github.com/zio/zio/issues/7301 | |
| .tap(f => ZIO.log(s"found $f")) | |
| .runCollect | |
| _ <- ZIO.log(s"found ${entries.size} entries") | |
| } yield () | |
| } | |
| Photos.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment