Crate stuck

source ·
Expand description

§Multi-threading task facility building on cooperative stackful coroutine

stuck provides a multi-threading runtime to serve lightweight concurrent tasks where you can use coroutine::suspension to cooperatively resume suspending coroutines.


Construct an runtime::Runtime to runtime::Runtime::spawn initial task.


  • Use task::spawn to spawn new task in running task. The spawned task will run concurrent with all other tasks.
  • Use task::session to create facilities to wake waiting tasks.
  • Use task::JoinHandle to join task result.



use std::time::Duration;

use stuck::channel::parallel;
use stuck::channel::prelude::*;
use stuck::{select, task, time};

fn main() {
    let (mut request_sender, request_receiver) = parallel::bounded(1);
    let (mut response_sender, mut response_receiver) = parallel::bounded(1);

    task::spawn(move || {
        for value in request_receiver.into_iter() {
            response_sender.send(value - 1).unwrap();

    let mut tasks = vec![6, 6, 6, 6];

    let mut sum = 0;
    loop {
        select! {
            r = <-response_receiver => if let Some(n) = r {
                sum += n;
            _ = request_sender<-tasks.pop().unwrap(), if !tasks.is_empty()  => if tasks.is_empty() {
            complete => break,
    println!("sum: {}", sum);
    assert_eq!(sum, 20);


  • Channel utilities for commnication across coroutines and tasks.
  • Cooperative coroutines in task.
  • Drop-in replacement of std::fs with no operations block scheduling thread.
  • Networking primitives for TCP/UDP communication.
  • Constructions to bootstrap stuck runtime.
  • Selectively read and write values to/from multiple selectables simultaneously.
  • Lightweight concurrent execution units based on coroutines.
  • Utilities to suspend running coroutines.


  • Select multiple selectables simultaneously for reading and writing


Attribute Macros§

  • Executes marked main function in configured runtime.
  • Executes marked test function in configured runtime.