{"id":13500969,"url":"https://github.com/majek/lua-channels","last_synced_at":"2025-03-17T05:32:19.017Z","repository":{"id":10350902,"uuid":"12488042","full_name":"majek/lua-channels","owner":"majek","description":"Go style channels in pure Lua","archived":false,"fork":false,"pushed_at":"2013-09-06T12:06:05.000Z","size":176,"stargazers_count":140,"open_issues_count":2,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-27T18:26:58.207Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/majek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-30T14:15:17.000Z","updated_at":"2024-12-21T09:38:01.000Z","dependencies_parsed_at":"2022-09-22T19:01:12.716Z","dependency_job_id":null,"html_url":"https://github.com/majek/lua-channels","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majek%2Flua-channels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majek%2Flua-channels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majek%2Flua-channels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majek%2Flua-channels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/majek","download_url":"https://codeload.github.com/majek/lua-channels/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243846976,"owners_count":20357294,"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":[],"created_at":"2024-07-31T22:01:20.960Z","updated_at":"2025-03-17T05:32:18.200Z","avatar_url":"https://github.com/majek.png","language":"Lua","readme":"[![Build Status](https://travis-ci.org/majek/lua-channels.png)](https://travis-ci.org/majek/lua-channels)\n\nLua-Channels\n============\n\n*Go style Channels for Lua*\n\nThis code is derived from libtask library by Russ Cox, mainly from\nchannel.c. Semantically channels as implemented here are quite\nsimilar to channels from the Go language.\n\nUsage\n-----\n\nThis is an example of using an unbuffered channel:\n\n```\nlocal task = require('lua-channels')\n\nlocal function counter(channel)\n   local i = 1\n   while true do\n       channel:send(i)\n       i = i + 1\n   end\nend\n\nlocal function main()\n    local channel = task.Channel:new()\n    task.spawn(counter, channel)\n    assert(channel:recv() == 1)\n    assert(channel:recv() == 2)\n    assert(channel:recv() == 3)\nend\n\ntask.spawn(main)\ntask.scheduler()\n```\n\nlua-channels exposes:\n\n * task.spawn(fun, [...]) - run fun as a coroutine with given\n                        parameters. You should use this instead of\n                        coroutine.create()\n\n * task.scheduler() - can be run only from the main thread, executes\n                    all the stuff, resumes the coroutines that are\n                    blocked on channels that became available. You\n                    can only do non-blocking sends / receives from\n                    the main thread.\n\n * task.Channel:new([buffer size]) - create a new channel with given size\n\n * task.chanalt(alts, can_block) - run alt / select / multiplex over\n                                 the alts structure. For example:\n\n * task.chanalt({{c = channel_1, op = task.RECV},\n              {c = channel_2, op = task.SEND, p = \"hello\"}}, true)\n\nThis will block current coroutine until it's possible to receive\nfrom channel_1 or send to channel_2. chanalt returns a number of\nstatement from alts that succeeded (1 or 2 here) and a received\nvalue if executed statement was RECV.\n\nFinally, if two alt statements can be fulfilled at the same time,\nwe use math.random() to decide which one should go first. So it\nmakes sense to initialize seed with something random. If you don't\nhave access to an entropy source you can do:\n\n```\n  math.randomseed(os.time())\n```\n\nbut beware, the results of random() will predictable to a attacker.\n\nInstalling\n----------\n\nYou may simply require src/lua-channels.lua from the source, or install\n`lua-channels` from [luarocks](http://luarocks.org).\n\n","funding_links":[],"categories":["Lua"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajek%2Flua-channels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmajek%2Flua-channels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajek%2Flua-channels/lists"}