{"id":13477932,"url":"https://github.com/smol-rs/async-task","last_synced_at":"2025-05-14T01:02:13.938Z","repository":{"id":37043470,"uuid":"262871328","full_name":"smol-rs/async-task","owner":"smol-rs","description":"Task abstraction for building executors","archived":false,"fork":false,"pushed_at":"2025-01-23T15:01:32.000Z","size":224,"stargazers_count":462,"open_issues_count":12,"forks_count":44,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-06T21:00:41.874Z","etag":null,"topics":["async","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/smol-rs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2020-05-10T20:38:51.000Z","updated_at":"2025-04-01T19:04:56.000Z","dependencies_parsed_at":"2023-09-25T22:52:52.444Z","dependency_job_id":"9ce10197-c5b7-4e01-8e6e-e85f4d713a8d","html_url":"https://github.com/smol-rs/async-task","commit_stats":{"total_commits":157,"total_committers":23,"mean_commits":6.826086956521739,"dds":0.5159235668789809,"last_synced_commit":"ca9dbe1db9c422fd765847fa91306e30a6bb58a9"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fasync-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fasync-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fasync-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fasync-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smol-rs","download_url":"https://codeload.github.com/smol-rs/async-task/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661718,"owners_count":21141451,"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","rust"],"created_at":"2024-07-31T16:01:50.006Z","updated_at":"2025-04-13T23:39:10.724Z","avatar_url":"https://github.com/smol-rs.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# async-task\n\n[![Build](https://github.com/smol-rs/async-task/actions/workflows/ci.yml/badge.svg)](\nhttps://github.com/smol-rs/async-task/actions)\n[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](\nhttps://github.com/smol-rs/async-task)\n[![Cargo](https://img.shields.io/crates/v/async-task.svg)](\nhttps://crates.io/crates/async-task)\n[![Documentation](https://docs.rs/async-task/badge.svg)](\nhttps://docs.rs/async-task)\n\nTask abstraction for building executors.\n\nTo spawn a future onto an executor, we first need to allocate it on the heap and keep some\nstate attached to it. The state indicates whether the future is ready for polling, waiting to\nbe woken up, or completed. Such a stateful future is called a *task*.\n\nAll executors have a queue that holds scheduled tasks:\n\n```rust\nlet (sender, receiver) = flume::unbounded();\n```\n\nA task is created using either `spawn()`, `spawn_local()`, or `spawn_unchecked()` which\nreturn a `Runnable` and a `Task`:\n\n```rust\n// A future that will be spawned.\nlet future = async { 1 + 2 };\n\n// A function that schedules the task when it gets woken up.\nlet schedule = move |runnable| sender.send(runnable).unwrap();\n\n// Construct a task.\nlet (runnable, task) = async_task::spawn(future, schedule);\n\n// Push the task into the queue by invoking its schedule function.\nrunnable.schedule();\n```\n\nThe `Runnable` is used to poll the task's future, and the `Task` is used to await its\noutput.\n\nFinally, we need a loop that takes scheduled tasks from the queue and runs them:\n\n```rust\nfor runnable in receiver {\n    runnable.run();\n}\n```\n\nMethod `run()` polls the task's future once. Then, the `Runnable`\nvanishes and only reappears when its `Waker` wakes the task, thus\nscheduling it to be run again.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n#### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmol-rs%2Fasync-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmol-rs%2Fasync-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmol-rs%2Fasync-task/lists"}