{"id":13624304,"url":"https://github.com/NodeGuy/channel","last_synced_at":"2025-04-15T21:30:33.020Z","repository":{"id":25702121,"uuid":"105304126","full_name":"NodeGuy/channel","owner":"NodeGuy","description":"Go-like channels for JavaScript","archived":true,"fork":false,"pushed_at":"2023-07-03T03:08:13.000Z","size":592,"stargazers_count":65,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-01T21:59:33.030Z","etag":null,"topics":["channel","concurrency","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NodeGuy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2017-09-29T18:21:51.000Z","updated_at":"2024-01-09T06:38:05.000Z","dependencies_parsed_at":"2024-01-14T08:07:03.653Z","dependency_job_id":null,"html_url":"https://github.com/NodeGuy/channel","commit_stats":{"total_commits":120,"total_committers":4,"mean_commits":30.0,"dds":"0.18333333333333335","last_synced_commit":"261a23f479a7c9df29f2afb4cf83147a0f6b8b83"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeGuy%2Fchannel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeGuy%2Fchannel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeGuy%2Fchannel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodeGuy%2Fchannel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NodeGuy","download_url":"https://codeload.github.com/NodeGuy/channel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223685173,"owners_count":17185794,"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":["channel","concurrency","javascript"],"created_at":"2024-08-01T21:01:41.194Z","updated_at":"2024-11-08T12:31:21.767Z","avatar_url":"https://github.com/NodeGuy.png","language":"JavaScript","funding_links":[],"categories":["javascript"],"sub_categories":[],"readme":"# Introduction\n\nThis is an idiomatic, minimally-opinionated `Channel` type for JavaScript that's\ninspired by [Go's channels](https://golang.org/ref/spec#Channel_types). It\nworks in browsers and in Node.js. If you know how to use an `Array` then you\nalready know most of how to use a `Channel`.\n\n## Why\n\nGo's use of channels for concurrency is amazing and with JavaScript's\nasync/await feature we have the basis for it as well. All that's missing is a\nsolid `Channel` type. There are existing libraries but I wanted an idiomatic\n`Channel` type that's simple and minimally-opinionated.\n\nThis document assumes you're familiar with Go's channels and why you'd want to\nuse them. For explanatory background, see my [blog\narticle](https://www.nodeguy.com/channels-for-javascript/) on the subject.\n\n## Installation\n\n```shell\n$ npm install @nodeguy/channel\n```\n\n## Basic Use\n\nCreate a channel with `Channel()`.\n\nTo send a value to a channel use `push`. To receive a value from a channel use\n`shift`. Always precede the method calls with `await`. Close the channel when\nthere are no more values to push.\n\n```JavaScript\nconst assert = require(`assert`);\nconst Channel = require(`@nodeguy/channel`);\n\nconst channel = Channel();\n\nconst send = async () =\u003e {\n  await channel.push(42);\n  await channel.close();\n};\n\nconst receive = async () =\u003e {\n  assert.equal(await channel.shift(), 42);\n  assert.equal(await channel.shift(), undefined);\n};\n\nawait Promise.all([send(), receive()]);\n```\n\nThe `push` and `shift` methods are usually called in different async functions.\nThey represent the two different ends of the channel and act to synchronize the\nbehavior of the async functions.\n\n# API\n\nThe API is in the [API.md](API.md) file.\n\n# Similar Projects\n\n- [Channel](https://github.com/gozala/channel)\n- [cochan](https://github.com/skozin/cochan)\n- [js-csp](https://github.com/ubolonton/js-csp)\n- [node-csp](https://github.com/olahol/node-csp)\n\n# Copyright\n\nCopyright 2017 [David Braun](https://www.NodeGuy.com/)\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthese files except in compliance with the License. You may obtain a copy of the\nLicense at `http://www.apache.org/licenses/LICENSE-2.0`. Unless required by\napplicable law or agreed to in writing, software distributed under the License\nis distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNodeGuy%2Fchannel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNodeGuy%2Fchannel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNodeGuy%2Fchannel/lists"}