{"id":33926692,"url":"https://github.com/kralloie/signaled","last_synced_at":"2025-12-12T10:28:42.602Z","repository":{"id":322115927,"uuid":"1062855286","full_name":"kralloie/signaled","owner":"kralloie","description":"Rust crate that provides a lightweight wrapper for binding callbacks on variable mutations.","archived":false,"fork":false,"pushed_at":"2025-11-02T18:07:57.000Z","size":256,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-02T18:11:22.071Z","etag":null,"topics":["crate","crates","crates-io","library","reactive","reactive-programming","rust","signal","slot"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/kralloie.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-09-23T20:33:03.000Z","updated_at":"2025-11-02T18:07:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kralloie/signaled","commit_stats":null,"previous_names":["kralloie/signaled"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/kralloie/signaled","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kralloie%2Fsignaled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kralloie%2Fsignaled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kralloie%2Fsignaled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kralloie%2Fsignaled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kralloie","download_url":"https://codeload.github.com/kralloie/signaled/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kralloie%2Fsignaled/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27680899,"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","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"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":["crate","crates","crates-io","library","reactive","reactive-programming","rust","signal","slot"],"created_at":"2025-12-12T10:28:39.837Z","updated_at":"2025-12-12T10:28:42.594Z","avatar_url":"https://github.com/kralloie.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/kralloie/signaled/refs/heads/main/assets/signaled.png\" width=\"200\"\u003e\n\n# Signaled\n\n[![Crates.io](https://img.shields.io/crates/d/signaled.svg?label=downloads)](https://crates.io/crates/signaled)\n[![Crates.io](https://img.shields.io/crates/v/signaled.svg)](https://crates.io/crates/signaled)\n[![Docs.rs](https://docs.rs/signaled/badge.svg)](https://docs.rs/signaled)\n\u003cimg src=\"https://github.com/kralloie/signaled/actions/workflows/tests.yml/badge.svg\" alt=\"test\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg\" alt=\"License\"\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\nA lightweight reactive programming library for Rust, providing a signal-slot mechanism. `Signaled\u003cT\u003e` holds a value and emits signals to registered callbacks when the value changes.\n\nThis library comes in two versions:\n- **`signaled::sync`**: A thread-safe implementation using `RwLock` and `Mutex`. Recommended for most applications.\n- **`signaled`**: A single-threaded implementation using `RefCell`. Ideal for contexts where thread safety is not required.\n\n## Features\n\n- **Reactive Updates**: Update a value and automatically emit signals to registered callbacks.\n- **Priority-Based Signals**: Signals are executed in descending priority order.\n- **Conditional Triggers**: Signals can have trigger functions to control callback execution.\n- **One-Time Signals**: Signals can be flagged as `once`. A `once` signal is automatically removed after its callback is successfully executed (i.e., when its trigger condition is met).\n\n---\n\n## Thread-Safe Usage (`signaled::sync`)\n\nThe `sync` module provides a fully thread-safe implementation suitable for multi-threaded applications. It uses `RwLock` and `Mutex` for interior mutability.\n\n### Example\n\n```rust\nuse signaled::sync::{Signaled, Signal};\nuse signaled::signal_sync;\nuse std::sync::{Arc, Mutex};\n\nlet signaled = Arc::new(Signaled::new(0));\nlet calls = Arc::new(Mutex::new(0));\n\nlet calls_clone = Arc::clone(\u0026calls);\nlet signal = signal_sync!(move |old: \u0026i32, new: \u0026i32| {\n    println!(\"Value changed: {} -\u003e {}\", old, new);\n    let mut lock = calls_clone.lock().unwrap();\n    *lock += 1;\n});\n\nsignaled.add_signal(signal).unwrap();\n\n// Set the value from different threads\nlet threads: Vec\u003c_\u003e = (1..=3).map(|i| {\n    let signaled_clone = Arc::clone(\u0026signaled);\n    std::thread::spawn(move || {\n        signaled_clone.set(i).unwrap();\n    })\n}).collect();\n\nfor handle in threads {\n    handle.join().unwrap();\n}\n\nassert_eq!(*calls.lock().unwrap(), 3);\nprintln!(\"Final value: {}\", signaled.get().unwrap());\n```\n\n### Error Handling (`sync`)\n\nMethods may return `SignaledError` for:\n- `PoisonedLock`: Attempted to acquire a poisoned `RwLock` or `Mutex`.\n- `WouldBlock`: A `try_` method failed to acquire a lock immediately.\n- `InvalidSignalId`: Provided a `Signal` ID that does not exist.\n\n### ⚠️ Deadlock Warning\nIncorrectly managing locks can lead to deadlocks. For example, holding a read lock on the `Signaled` value while trying to call `set` from the same thread will deadlock. Non-blocking `try_*` methods are provided as an alternative.\n\n---\n\n## Single-Threaded Usage (`signaled`)\n\nThis is a high-performance version for single-threaded contexts. It uses `RefCell` for interior mutability and provides runtime borrow checking.\n\n### Example\n\n```rust\nuse signaled::{Signaled, Signal, signal};\n\nlet signaled = Signaled::new(0);\nlet high_priority = signal!(|old: \u0026i32, new: \u0026i32| println!(\"High: Old: {}, New: {}\", old, new));\nhigh_priority.set_priority(10);\n\nlet conditional = signal!(|old: \u0026i32, new: \u0026i32| println!(\"Conditional: Old: {}, New: {}\", old, new));\nconditional.set_trigger(|old: \u0026i32, new: \u0026i32| *new \u003e *old + 5).unwrap();\n\nsignaled.add_signal(high_priority).unwrap();\nsignaled.add_signal(conditional).unwrap();\n\nsignaled.set(10).unwrap();\nsignaled.set(3).unwrap();\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eConsole Output\u003c/summary\u003e\n\n```console\nHigh: Old: 0, New: 10\nConditional: Old: 0, New: 10\nHigh: Old: 10, New: 3\n```\n\n\u003c/details\u003e\n\n### Error Handling (Single-Threaded)\n\nMethods may return `SignaledError` for:\n- `BorrowError`: Attempted to immutably borrow a value already mutably borrowed.\n- `BorrowMutError`: Attempted to mutably borrow a value already borrowed.\n- `InvalidSignalId`: Provided a `Signal` ID that does not exist.\n\n### ⚠️ Re-entrant Calls\nRecursive or re-entrant calls (e.g., calling `set` from within a signal's callback) may cause a panic due to `RefCell` borrow errors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkralloie%2Fsignaled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkralloie%2Fsignaled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkralloie%2Fsignaled/lists"}