{"id":17834994,"url":"https://github.com/carlosedp/zio-channel","last_synced_at":"2025-03-19T14:31:36.152Z","repository":{"id":154417050,"uuid":"624636717","full_name":"carlosedp/zio-channel","owner":"carlosedp","description":"Prototype library for Go-like channels in Scala 3 / ZIO 2","archived":false,"fork":false,"pushed_at":"2024-12-27T14:02:54.000Z","size":149,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T19:21:05.391Z","etag":null,"topics":["channels","ipc","scala","threading","zio"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/carlosedp.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"carlosedp","patreon":"carlosedp"}},"created_at":"2023-04-06T23:11:16.000Z","updated_at":"2024-12-27T14:02:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"981d34fd-5ea2-48ea-9cfa-509d143a07f5","html_url":"https://github.com/carlosedp/zio-channel","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosedp%2Fzio-channel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosedp%2Fzio-channel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosedp%2Fzio-channel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosedp%2Fzio-channel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carlosedp","download_url":"https://codeload.github.com/carlosedp/zio-channel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243997127,"owners_count":20380981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["channels","ipc","scala","threading","zio"],"created_at":"2024-10-27T20:16:08.213Z","updated_at":"2025-03-19T14:31:35.897Z","avatar_url":"https://github.com/carlosedp.png","language":"Scala","funding_links":["https://github.com/sponsors/carlosedp","https://patreon.com/carlosedp"],"categories":[],"sub_categories":[],"readme":"# Zio-channel, Go-like channels for your ZIO application\n\nChannel is a construct that provides a meeting point for two fibers to communicate. It requires both the sender and receiver to \"meet\" to exchange messages, blocking one until the other is available. Channels also can be constructed with a buffer to provide some capacity slots allowing the fibers to continue running until the channel gets full.\n\nThe concept comes from [Golang](https://go.dev/tour/concurrency/2) Channels, Erlang [message passing](https://www.erlang.org/blog/message-passing/) and also [Stackless Python](https://stackless.readthedocs.io/en/2.7-slp/library/stackless/channels.html) but now in a functional paradigm as a ZIO library for Scala applications.\n\nThe idea to create this came when I read Adam Warsky's [post](https://softwaremill.com/go-like-channels-using-project-loom-and-scala/) implementing this using Project Loom on Scala Ox lib.\n\nChannels can be unbuffered, with only one slot or buffered with N slots. Fibers sending or receiving to this channel block if it's an unbuffered channel or once the buffered channel becomes full.\n\nThis is still a prototype with basic functionality to gather interest and ideas for improvements. The lib is currently built for Scala 3.3 on JVM, Scala Native and ScalaJs. I don't plan to support Scala 2.\n\n[![zio-channel Scala version support](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel)\n[![zio-channel Scala version support](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel/latest-by-scala-version.svg?platform=native0.4)](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel)\n[![zio-channel Scala version support](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel/latest-by-scala-version.svg?platform=sjs1)](https://index.scala-lang.org/carlosedp/zio-channel/zio-channel)\n[![Sonatype Snapshots](https://img.shields.io/nexus/s/com.carlosedp/zio-channel_3?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/com/carlosedp//zio-channel_3/)\n\n[![Scala CI](https://github.com/carlosedp/zio-channel/actions/workflows/scala.yml/badge.svg)](https://github.com/carlosedp/zio-channel/actions/workflows/scala.yml)\n[![codecov](https://codecov.io/gh/carlosedp/zio-channel/branch/main/graph/badge.svg?token=Wln0zziII9)](https://codecov.io/gh/carlosedp/zio-channel)[![Scaladoc](https://www.javadoc.io/badge/com.carlosedp/zio-channel_3.svg?color=blue\u0026label=Scaladoc)](https://javadoc.io/doc/com.carlosedp/zio-channel_3/latest)\n\n## Installation\n\nAdd to your `build.sbt` / `build.sc` / scala-cli:\n\n```scala\n// For Mill:\ndef ivyDeps = Agg(ivy\"com.carlosedp::zio-channel:0.7.0\")\n// or for SBT:\nlibraryDependencies += \"com.carlosedp\" %% \"zio-channel\" % \"0.7.0\"\n// or in scala-cli app:\n//\u003e using dep \"com.carlosedp::zio-channel:0.7.0\n```\n\n## Usage\n\nBelow is a simple example that creates a one-slot channel (unbuffered) where the forked receiver blocks waiting for a message in the channel and gets unblocked when the main fiber sends a message allowing it to use the value and continue. Save the file locally and run with [scala-cli](https://scala-cli.virtuslab.org/):\n\n```scala\n//\u003e using scala 3\n//\u003e using dep dev.zio::zio:2.1.9\n//\u003e using dep com.carlosedp::zio-channel:0.7.0\n\nimport zio.*\nimport zio.channel.*\n\nobject ZioChannel extends ZIOAppDefault:\n  val run =\n    for\n      chan \u003c- Channel.make[String]\n      // This receiver will block waiting for messages\n      f1 \u003c- (chan.receive.tap(i =\u003e Console.printLine(s\"Receiver received $i\")) *\u003e\n              Console.printLine(\"Receiver resumed\")).fork\n      _ \u003c- Console.printLine(\"Sender in main fiber will send message...\")\n      _ \u003c- chan.send(\"Hi receiver 1!\") // This will send and unblock the receiver\n      _ \u003c- f1.join\n      _ \u003c- Console.printLine(\"Done\")\n    yield ()\n```\n\nRun it with `scala-cli examples/src/sample-readme.scala`.\n\nTo create a multiple slot(buffered) channel where the fibers doesn't block sending or receiving to it until full, use `chan \u003c- Channel.make[Int](5)`.\n\nIt's also possible to get the channel `status` to check the amount of messages waiting, positive for senders and negative for receivers and `close` a channel to remove all messages and unblock the waiting fibers.\n\nThere are some additional examples at [./examples/src/](./examples/src/) including `channel.select` to receive from a collection of channels. all of them can be run with scala-cli.\n\nCheck benchmarks comparing zio-channel with native ZIO queues for latest commit to main [here](https://jmh.morethan.io/?source=https://raw.githubusercontent.com/carlosedp/zio-channel/main/benchmark-files/jmh-result-latest.json). The benchmark shows the time taken to send and receive 1000 messages (smaller is better).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosedp%2Fzio-channel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlosedp%2Fzio-channel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosedp%2Fzio-channel/lists"}