Compare commits

..

No commits in common. "main" and "v0.0.1" have entirely different histories.
main ... v0.0.1

4 changed files with 10 additions and 27 deletions

2
Cargo.lock generated
View File

@ -88,7 +88,7 @@ dependencies = [
[[package]]
name = "noworkers"
version = "0.0.1"
version = "0.1.0"
dependencies = [
"anyhow",
"tokio",

View File

@ -4,7 +4,6 @@ resolver = "2"
[workspace.package]
version = "0.0.1"
license = "MIT"
[workspace.dependencies]
noworkers = { path = "crates/noworkers" }

View File

@ -5,12 +5,6 @@ Manage concurrent tasks with optional limits, cancellation, and first-error prop
Inpired by golang (errgroups)
## Disclaimer
The library is still new, and as such the API is subject to change, I don't expect changes to the add and wait functions, but the rest may change. I might also move to custom error types, and or removing the tokio_utils entirely to slim down the package. It shouldn't affect the user too much however.
The crate is in production, and has seen extensive use
## Features
- **Unlimited or bounded concurrency** via `with_limit(usize)`.
@ -31,39 +25,33 @@ Then in your code:
```rust
use noworkers::Workers;
use tokio_util::sync::CancellationToken;
```
## Quick Example
```rust
```rust,no_run
use noworkers::Workers;
use tokio_util::sync::CancellationToken;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a worker group with up to 5 concurrent tasks
let mut workers = Workers::new();
// Limit amount of concurrent workers
workers.with_limit(5);
// Adds cancellation signal
workers.with_cancel_task(async move {
// send cancellation to tasks after 60 seconds
tokio::time::sleep(std::time::Duration::from_secs(60)).await
});
workers
.with_limit(5)
.with_cancel(&CancellationToken::new());
// Spawn 10 async jobs
for i in 0..10 {
// Work is done immediatley, so this will wait in two batches of 1 seconds each (because of limit)
workers.add(move |cancel_token| async move {
// optional tokio::select, if you use cancellation for your tasks, if not just do your work
// Respect cancellation, or not, if you don't care about blocking forever
tokio::select! {
// Do work, in this case just sleep
_ = tokio::time::sleep(tokio::time::Duration::from_secs(1)) => {
println!("Job {i} done");
Ok(())
}
// If we receive cancel we close
_ = cancel_token.cancelled() => {
println!("Job {i} cancelled");
Ok(())
@ -107,9 +95,5 @@ async fn main() -> anyhow::Result<()> {
Dual-licensed under **MIT** or **Apache-2.0**.
See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE) for details.
## Contribute
Simply create an issue here or pr https://github.com/kjuulh/noworkers.git, development happens publicly at: https://git.front.kjuulh.io/kjuulh/noworkers.
```

View File

@ -3,7 +3,7 @@ name = "noworkers"
edition = "2024"
readme = "../../README.md"
version.workspace = true
license.workspace = true
license = "MIT or APACHE"
repository = "https://git.front.kjuulh.io/kjuulh/noworkers"
authors = ["kjuulh <contact@kasperhermansen.com>"]
description = "A small asyncronous worker pool manages thread pool limiting, cancellation and error propogation, inspired by golangs errgroup (requires tokio)"