Kasper Juul Hermansen bbda5ad934
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): v0.0.4 (#4)
chore(release): 0.0.4

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/drop-queue/pulls/4
2025-07-22 22:21:11 +02:00
2025-07-22 22:17:17 +02:00
2025-07-22 22:01:14 +02:00
2025-07-22 22:01:14 +02:00
2025-07-22 22:17:17 +02:00
2025-07-22 22:21:11 +02:00
2025-07-22 22:21:11 +02:00
2025-07-22 22:12:40 +02:00
2025-07-22 22:12:40 +02:00

🧊 drop-queue

drop-queue is a simple, composable async drop queue for Rust — built to run queued tasks in FIFO order and ensure graceful shutdown via draining. It's useful in lifecycle-managed environments (e.g., notmad) or as a lightweight alternative until async drop is stabilized in Rust.

💡 Tasks are executed one at a time. If the queue is marked for draining, no further items can be added.


Features

  • Assign one-off async tasks (closures) to a queue
  • FIFO task processing
  • Draining mechanism to flush the queue before shutdown
  • Optional integration with notmad for graceful component lifecycle control
  • Send + Sync + 'static guaranteed

🚀 Usage

Add to Cargo.toml

[dependencies]
drop-queue = "*"

Enable notmad integration (optional)

[dependencies]
drop-queue = { version = "*", features = ["notmad"] }

🛠 Example

use drop-queue::DropQueue;
use tokio::sync::oneshot;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let queue = DropQueue::new();

    let (tx, rx) = oneshot::channel();

    queue.assign(|| async move {
        println!("Running closure task");
        tx.send(()).unwrap();
        Ok(())
    })?;

    queue.process_next().await?;

    rx.await?;

    Ok(())
}

🔁 Lifecycle with notmad

If using the notmad lifecycle framework:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let queue = drop-queue::DropQueue::new();
    let app = notmad::Mad::new().add(queue);
    app.run().await?;
    Ok(())
}

This will process tasks until the cancellation token is triggered, e.g., via SIGINT.


🔒 Drain Mode

You can signal the queue to stop accepting new items and finish processing the current ones:

queue.drain().await?;

After this call, any further assign() will panic.


🧪 Tests

Run the test suite using:

cargo test

📜 License

MIT

Description
No description provided
Readme 61 KiB
v0.0.4 Latest
2025-07-22 22:21:23 +02:00
Languages
Rust 100%