{"id":16985729,"url":"https://github.com/jack-ji/zig-async","last_synced_at":"2025-03-17T09:30:31.254Z","repository":{"id":105140420,"uuid":"494136030","full_name":"Jack-Ji/zig-async","owner":"Jack-Ji","description":"A simple and easy to use async task library for zig.","archived":false,"fork":false,"pushed_at":"2024-05-29T02:25:41.000Z","size":36,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-16T00:17:00.483Z","etag":null,"topics":["async","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/Jack-Ji.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":"2022-05-19T15:50:52.000Z","updated_at":"2025-02-12T22:03:22.000Z","dependencies_parsed_at":"2024-10-27T12:48:20.620Z","dependency_job_id":"ff3b8e43-e0f6-43ba-92c9-3bfd2c3cba23","html_url":"https://github.com/Jack-Ji/zig-async","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jack-Ji%2Fzig-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jack-Ji%2Fzig-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jack-Ji%2Fzig-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jack-Ji%2Fzig-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jack-Ji","download_url":"https://codeload.github.com/Jack-Ji/zig-async/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858148,"owners_count":20359253,"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":["async","zig"],"created_at":"2024-10-14T02:44:04.818Z","updated_at":"2025-03-17T09:30:30.958Z","avatar_url":"https://github.com/Jack-Ji.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig-async\nAn simple and easy to use async task library for zig.\n\n## Async Task\nTask running in separate thread, returns `Future` after launched.\n`Future` represents task's return value in the future, which can be queried by using its waiting methods.\nThe wrapped data within `Future` will be automatically destroyed if supported by struct (has `deinit` method);\n\n```zig\nconst Result = struct {\n    const Self = @This();\n\n    allocator: std.mem.Allocator,\n    c: u32,\n\n    pub fn init(allocator: std.mem.Allocator, _c: u32) !*Self {\n        var self = try allocator.create(Self);\n        self.* = .{\n            .allocator = allocator,\n            .c = _c,\n        };\n        return self;\n    }\n\n    /// Will be called automatically when destorying future\n    pub fn deinit(self: *Self) void {\n        self.allocator.destroy(self);\n    }\n};\n\nfn add(a: u32, b: u32) !*Result {\n    return try Result.init(std.testing.allocator, a + b);\n}\n\nconst MyTask = Task(add);\nvar future = try MyTask.launch(std.testing.allocator, .{ 2, 1 });\ndefer future.deinit();\nconst ret = future.wait();\ntry testing.expectEqual(@as(u32, 3), if (ret) |d| d.c else |_| unreachable);\n```\n\n## Channel\nGeneric message queue used for communicating between threads.\nCapable of free memory automatically if supported by embedded struct (has `deinit` method).\n\n```zig\nconst MyData = struct {\n    d: i32,\n\n    /// Will be called automatically when destorying popped result\n    pub fn deinit(self: *@This()) void {\n    }\n};\n\nconst MyChannel = Channel(MyData);\nvar channel = try MyChannel.init(std.testing.allocator);\ndefer channel.deinit();\n\ntry channel.push(.{ .d = 1 });\ntry channel.push(.{ .d = 2 });\ntry channel.push(.{ .d = 3 });\ntry channel.push(.{ .d = 4 });\ntry channel.push(.{ .d = 5 });\n\ntry testing.expect(channel.pop().?.d, 1);\n\nvar result = channel.popn(3).?;\ndefer result.deinit();\ntry testing.expect(result.elements[0].d == 2);\ntry testing.expect(result.elements[1].d == 3);\ntry testing.expect(result.elements[2].d == 4);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjack-ji%2Fzig-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjack-ji%2Fzig-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjack-ji%2Fzig-async/lists"}