{"id":13632513,"url":"https://github.com/smol-rs/event-listener","last_synced_at":"2025-05-14T00:07:33.940Z","repository":{"id":41478564,"uuid":"264492083","full_name":"smol-rs/event-listener","owner":"smol-rs","description":"Notify async tasks or threads","archived":false,"fork":false,"pushed_at":"2025-01-25T14:44:37.000Z","size":316,"stargazers_count":467,"open_issues_count":4,"forks_count":34,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-08T00:08:53.205Z","etag":null,"topics":["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-16T17:41:11.000Z","updated_at":"2025-04-24T16:02:28.000Z","dependencies_parsed_at":"2023-11-15T05:31:47.629Z","dependency_job_id":"1db7215f-1fc4-4a4f-a709-0f5dbd683a22","html_url":"https://github.com/smol-rs/event-listener","commit_stats":{"total_commits":191,"total_committers":18,"mean_commits":10.61111111111111,"dds":0.7225130890052356,"last_synced_commit":"633b2c6336232d0854fd735a6499305b9185c6d1"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fevent-listener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fevent-listener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fevent-listener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smol-rs%2Fevent-listener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smol-rs","download_url":"https://codeload.github.com/smol-rs/event-listener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043779,"owners_count":22005014,"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":["rust"],"created_at":"2024-08-01T22:03:05.403Z","updated_at":"2025-05-14T00:07:33.922Z","avatar_url":"https://github.com/smol-rs.png","language":"Rust","funding_links":[],"categories":["Rust","Parallel and Async Library"],"sub_categories":[],"readme":"# event-listener\n\n[![Build](https://github.com/smol-rs/event-listener/workflows/CI/badge.svg)](\nhttps://github.com/smol-rs/event-listener/actions)\n[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](\nhttps://github.com/smol-rs/event-listener)\n[![Cargo](https://img.shields.io/crates/v/event-listener.svg)](\nhttps://crates.io/crates/event-listener)\n[![Documentation](https://docs.rs/event-listener/badge.svg)](\nhttps://docs.rs/event-listener)\n\nNotify async tasks or threads.\n\nThis is a synchronization primitive similar to [eventcounts] invented by Dmitry Vyukov.\n\nYou can use this crate to turn non-blocking data structures into async or blocking data\nstructures. See a [simple mutex] implementation that exposes an async and a blocking interface\nfor acquiring locks.\n\n[eventcounts]: https://www.1024cores.net/home/lock-free-algorithms/eventcounts\n[simple mutex]: ./examples/mutex.rs\n\n## Examples\n\nWait until another thread sets a boolean flag:\n\n```rust\nuse std::sync::atomic::{AtomicBool, Ordering};\nuse std::sync::Arc;\nuse std::thread;\nuse std::time::Duration;\nuse event_listener::Event;\n\nlet flag = Arc::new(AtomicBool::new(false));\nlet event = Arc::new(Event::new());\n\n// Spawn a thread that will set the flag after 1 second.\nthread::spawn({\n    let flag = flag.clone();\n    let event = event.clone();\n    move || {\n        // Wait for a second.\n        thread::sleep(Duration::from_secs(1));\n\n        // Set the flag.\n        flag.store(true, Ordering::SeqCst);\n\n        // Notify all listeners that the flag has been set.\n        event.notify(usize::MAX);\n    }\n});\n\n// Wait until the flag is set.\nloop {\n    // Check the flag.\n    if flag.load(Ordering::SeqCst) {\n        break;\n    }\n\n    // Start listening for events.\n    let listener = event.listen();\n\n    // Check the flag again after creating the listener.\n    if flag.load(Ordering::SeqCst) {\n        break;\n    }\n\n    // Wait for a notification and continue the loop.\n    listener.wait();\n}\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or https://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%2Fevent-listener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmol-rs%2Fevent-listener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmol-rs%2Fevent-listener/lists"}