{"id":16098996,"url":"https://github.com/hellerve/pi","last_synced_at":"2026-02-16T12:32:51.712Z","repository":{"id":79626344,"uuid":"71906347","full_name":"hellerve/pi","owner":"hellerve","description":"A π-calculus based greenthreading actor concurrency lightweight [mumble]","archived":false,"fork":false,"pushed_at":"2016-11-16T18:36:30.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T00:34:52.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellerve.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-25T14:39:14.000Z","updated_at":"2023-09-08T17:16:18.000Z","dependencies_parsed_at":"2023-05-13T22:00:15.324Z","dependency_job_id":null,"html_url":"https://github.com/hellerve/pi","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hellerve/pi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellerve%2Fpi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellerve%2Fpi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellerve%2Fpi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellerve%2Fpi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellerve","download_url":"https://codeload.github.com/hellerve/pi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellerve%2Fpi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29507903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-10-09T18:25:21.746Z","updated_at":"2026-02-16T12:32:51.670Z","avatar_url":"https://github.com/hellerve.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# pi\n\nGreenthreading in zepto with channels.\n\nIt is extremely primitive and small (42 LOC in total).\n\n## Installation\n```\nzeps install hellerve/pi\n```\n\n## Usage\n\nThe two main concepts in pi are channels and actors.\n\nActors are created by forking, i.e. saying that a function\nshould be scheduled to run at some point (thread-like).\nThey can also `yield`, which means they tell the scheduler\nthey want to give up their role as currently running and\nbe awoken when it's their next turn.\n\nChannels are a way for actors to communicate, i.e. send\nvalues from one actor to another. Actors can put values\ninto the channel and take from the channel. If the channel\nis empty, the call to `chan:take` will block the current actor\nuntil it can provide a value.\n\nLet's dive into an example.\n\n```clojure\n(define channel (chan:empty))\n\n(fork (lambda ()\n        (begin\n          (write \"first thread\")\n          (write (++ \"Received: \" (chan:take channel))))))\n(fork (lambda ()\n        (begin\n          (write \"second thread\")\n          (chan:put channel \"Hello, I will be printed\"))))\n(fork (lambda ()\n        (begin\n          (write \"third thread\")\n          (chan:put channel \"Noone will take me :(\"))))\n(yield)\n```\n\nThis is short, but dense, and it is hard to wrap your head around\nwhat will happen. So, let's get through this line by line.\n\nFirst, we create an empty channel. Then we `fork` a thread. It\nwill print out `first thread` and then be put back to sleep. The\nsecond thread will print and the put something into the channel.\nThen the third thread will awake, print and put something into the\nchannel. At this point, the first thread will be woken up, realize that\nthere is something in the channel and happily print\n`Received: Hello, I will be printed`. The second value in the channel\nwill not be taken and so will be swallowed when the program terminates.\nThe call to `yield` at the end ensures the main thread gives up control\nflow.\n\nThere is also a `chan:select` statement that will query a collection\nof channels and take from the first channel that contains data.\n\n```clojure\n(define channel  (chan:empty))\n(define channel2 (chan:empty))\n\n(fork (lambda ()\n        (chan:select\n          (channel\n            ($ (write %)))\n          (channel2\n            ($ (write \"And now for something completely different!\"))))))\n\n(fork (lambda () (chan:put channel2 \"hello there\")))\n(yield)\n```\n\nThis will select the second channel (as there is data in there), take\ndata from it, completely ignore it, and write `And now for something completely different!` to the standard output.\n\n## How?\n\nThe magic of continuations as values and mutable global data (_yuck_).\n\n\u003cbr/\u003e\nHave fun!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellerve%2Fpi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellerve%2Fpi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellerve%2Fpi/lists"}