sync_select

Crates.iosync_select
lib.rssync_select
version0.1.0
sourcesrc
created_at2024-11-08 19:25:25.256215
updated_at2024-11-08 19:25:25.256215
descriptionA short-circuiting (verbose) `std::thread::scope`.
homepage
repository
max_upload_size
id1441465
size4,177
Evan Schwartzentruber (splurf)

documentation

README

sync_select

A short-circuiting (verbose) std::thread::scope.

Example

use std::{thread::sleep, time::Duration};

use sync_select::*;

fn main() {
    let s = SyncSelect::new();

    // Task A (3rd to finish)
    s.spawn(|| sleep(Duration::from_secs(3)));

    // Task B (1st to finish => Subtask 1)
    s.spawn_with(|s| {
        // Task C (subtask of B) (1st to finish)
        s.spawn(|| sleep(Duration::from_secs(1)));

        // Task D (subtask of B) (2nd to finish)
        s.spawn(|| sleep(Duration::from_secs(2)));
    });

    // In this specific scenario, Task B is first to die,
    // because it short-circuits due to one of it's subtasks
    // finishing. This causes the root to short-circuit,
    // resulting in the program exiting.

    // Note: scopes automatically short-circuit when dropped.
}

Notes

  • There is no "borrow non-'static data" functionality.

Todo

  • Better ergonomics
    • scope(...) function or something.
    • Maybe build a macro select! similar to tokio's select! macro.
Commit count: 0

cargo fmt