{"id":32842240,"url":"https://github.com/moonbitlang/async","last_synced_at":"2026-03-02T07:11:41.422Z","repository":{"id":304935630,"uuid":"1011557403","full_name":"moonbitlang/async","owner":"moonbitlang","description":"async programming library for MoonBit","archived":false,"fork":false,"pushed_at":"2026-02-28T10:13:39.000Z","size":1802,"stargazers_count":58,"open_issues_count":7,"forks_count":10,"subscribers_count":5,"default_branch":"main","last_synced_at":"2026-02-28T11:33:18.615Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"MoonBit","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/moonbitlang.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-01T02:24:59.000Z","updated_at":"2026-02-27T09:37:19.000Z","dependencies_parsed_at":"2026-01-11T00:00:26.274Z","dependency_job_id":null,"html_url":"https://github.com/moonbitlang/async","commit_stats":null,"previous_names":["moonbitlang/async"],"tags_count":51,"template":false,"template_full_name":null,"purl":"pkg:github/moonbitlang/async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonbitlang%2Fasync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonbitlang%2Fasync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonbitlang%2Fasync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonbitlang%2Fasync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moonbitlang","download_url":"https://codeload.github.com/moonbitlang/async/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonbitlang%2Fasync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29994648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-11-08T04:00:39.294Z","updated_at":"2026-03-02T07:11:41.386Z","avatar_url":"https://github.com/moonbitlang.png","language":"MoonBit","funding_links":[],"categories":["Examples and Projects","\u003ca name=\"MoonBit\"\u003e\u003c/a\u003eMoonBit"],"sub_categories":[],"readme":"# Asynchronous programming library for MoonBit\n\nThis library provides basic asynchronous IO functionality for MoonBit,\nas well as useful asynchronous programming facilities.\nCurrently, this library only supports native/LLVM backends on Linux/MacOS.\n\nAPI document is available at \u003chttps://mooncakes.io/docs/moonbitlang/async\u003e.\nYou can also find small examples in `examples`,\nthese examples can be run via `moon run -C examples examples/\u003cexample-name\u003e` in project root.\nYoun can find a brief introduction to some examples in `examples/README.md`,\nincluding the topics each example covers.\n\nWARNING: this library is current experimental, API is subject to future change.\n\n## Installation\nIn your MoonBit project root, run:\n```bash\nmoon add moonbitlang/async@0.16.7\n```\nThis library provides the following packages:\n\n- `moonbitlang/async`: most basic asynchronous operations\n- `moonbitlang/async/socket`: TCP and UDP socket\n- `moonbitlang/async/tls`: TLS support via OpenSSL\n- `moonbitlang/async/stdio`: operations on standard output channels\n- `moonbitlang/async/pipe`: operations on pipes\n- `moonbitlang/async/fs`: file system operations, such as file IO and directory reading\n- `moonbitlang/async/process`: spawning system process\n- `moonbitlang/async/aqueue`: asynchronous queue data structure for inter-task communication\n- `moonbitlang/async/semaphore`: semaphore for concurrency control\n- `moonbitlang/async/cond_var`: condition variable with broadcasting support\n- `moonbitlang/async/io`: generic IO abstraction \u0026 utilities, such as buffering\n- `moonbitlang/async/http`: HTTP client and server support. Features:\n    - HTTPS client support\n    - `CONNECT` based HTTP/HTTPS proxy support\n- `moonbitlang/async/websocket`: WebSocket client and server support. Features:\n    - TLS encrypted WebSocket (`wss://`) support\n    - `CONNECT` based HTTP/HTTPS proxy support\n    - native integration with `moonbitlang/async/http`\n\nTo use these packages, add them to the `import` field of `moon.pkg.json`.\n\n## Features\n\n- [X] TCP/UDP socket\n- [X] DNS resolution\n- [X] TLS support\n- [X] HTTP support\n- [X] timer\n- [X] pipe\n- [X] asynchronous file system operations\n- [X] process manipulation\n- [ ] signal handling\n- [ ] file system watching\n- [X] structured concurrency\n- [X] cooperative multi tasking\n- [X] IO worker thread\n- [X] native integration with the MoonBit language\n- [X] Linux support (`epoll`)\n- [X] MacOS support (`kqueue`)\n- [X] Windows support (`IOCP`)\n- [ ] WASM backend\n- [X] Javascript backend\n    - [X] integration with JavaScript promise and Web API `ReadableStream`\n    - [X] all IO-independent API, including:\n        - `moonbitlang/async`\n        - `moonbitlang/async/io`\n        - `moonbitlang/async/aqueue`\n        - `moonbitlang/async/semaphore`\n        - `moonbitlang/async/cond_var`\n    - [X] HTTP Client API support in `@http` using fetch API\n    - [ ] implement other IO primitives in JavaScript using Node.js\n\n\n## Structured concurrency and error propagation\n`moonbitlang/async` features *structured concurrency*.\nIn `moonbitlang/async`, every asynchronous task must be spawned in a *task group*.\nTask groups can be created with the `with_task_group` function\n\n```moonbit\nasync fn[X] with_task_group(async (TaskGroup[X]) -\u003e X)  -\u003e X\n```\n\nWhen `with_task_group` returns,\nit is guaranteed that all tasks spawned in the group already terminate,\nleaving no room for orphan task and resource leak.\n\nIf any child task in a task group fail with error,\nall other tasks in the group will be cancelled.\nSo there will be no silently ignored error.\n\nFor more behavior detail and useful API, consult the API document.\n\n## Task cancellation\nIn `moonbitlang/async`, all asynchronous operations are by default cancellable.\nSo no need to worry about accidentally creating uncancellable task.\n\nIn `moonbitlang/async`, when a task is cancelled,\nit will receive an error at where it suspended.\nThe cancelled task can then perform cleanup logic using `try .. catch`.\nSince most asynchronous operations may throw other error anyway,\ncorrect error handling automatically gives correct cancellation handling,\nso most of the time correct cancellation handling just come for free in `moonbitlang/async`.\n\nCurrently, it is not allowed to perform other asynchronous operation after a task is cancelled.\nThose operations will be cancelled immediately if current task is already cancelled.\nSpawn a task in some parent context if asynchronous cleanup is necessary.\n\n## Caveats\n\nCurrently, `moonbitlang/async` features a single-threaded, cooperative multitasking model.\nWith this single-threaded model,\ncode without suspension point can always be considered atomic.\nSo no need for expensive lock and less bug.\nHowever, this model also come with some caveats:\n\n- task scheduling can only happen when current task suspend itself,\nby performing some asynchronous IO operation or manually calling `@async.pause`.\nIf you perform heavy computation loop without pausing from time to time,\nthe whole program will be blocked until the loop terminates,\nand other task will not get executed before that.\nSimilarly, performing blocking IO operation **not** provided by `moonbitlang/async`\nmay block the whole program as well\n\n- in the same way, task cancellation can only happen when a task is in suspended state\n(blocked by IO operation or manually `pause`'ed)\n\n- although internally `moonbitlang/async` may use OS threads to perform some IO job,\nuser code can only utilize one hardware processor\n\nThere are several other points to notice when using this library:\n\n- At most one task can read/write to socket etc. at anytime, to avoid race condition.\nIf multiple reader/writer is desired,\nyou should create a dedicated worker task for reading/writing\nand use `@async.Queue` to distribute/gather data\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonbitlang%2Fasync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoonbitlang%2Fasync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonbitlang%2Fasync/lists"}