5 Commits

Author SHA1 Message Date
41832dead4 chore(release): v0.0.2 (#2)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.0.2

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/noworkers/pulls/2
2025-07-01 16:02:23 +02:00
8b1ef0c2cb feat: clarify readme
All checks were successful
continuous-integration/drone/push Build is passing
2025-07-01 16:02:05 +02:00
688e742f20 feat: set mit
All checks were successful
continuous-integration/drone/push Build is passing
2025-07-01 15:46:50 +02:00
c6dbf5f4ea feat use mit license 2025-07-01 15:46:33 +02:00
8f4d61b9e1 docs: correct
All checks were successful
continuous-integration/drone/push Build is passing
2025-07-01 15:43:27 +02:00
5 changed files with 33 additions and 11 deletions

View File

@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.0.2] - 2025-07-01
### Added
- clarify readme
- set mit
- feat use mit license
### Docs
- correct
## [0.0.1] - 2025-07-01 ## [0.0.1] - 2025-07-01
### Added ### Added

2
Cargo.lock generated
View File

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

View File

@@ -3,7 +3,8 @@ members = ["crates/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "0.0.1" version = "0.0.2"
license = "MIT"
[workspace.dependencies] [workspace.dependencies]
noworkers = { path = "crates/noworkers" } noworkers = { path = "crates/noworkers" }

View File

@@ -25,33 +25,39 @@ Then in your code:
```rust ```rust
use noworkers::Workers; use noworkers::Workers;
use tokio_util::sync::CancellationToken;
``` ```
## Quick Example ## Quick Example
```rust,no_run ```rust
use noworkers::Workers; use noworkers::Workers;
use tokio_util::sync::CancellationToken;
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
// Create a worker group with up to 5 concurrent tasks // Create a worker group with up to 5 concurrent tasks
let mut workers = Workers::new(); let mut workers = Workers::new();
workers // Limit amount of concurrent workers
.with_limit(5) workers.with_limit(5);
.with_cancel(&CancellationToken::new());
// 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
});
// Spawn 10 async jobs // Spawn 10 async jobs
for i in 0..10 { 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 { workers.add(move |cancel_token| async move {
// Respect cancellation, or not, if you don't care about blocking forever // optional tokio::select, if you use cancellation for your tasks, if not just do your work
tokio::select! { tokio::select! {
// Do work, in this case just sleep
_ = tokio::time::sleep(tokio::time::Duration::from_secs(1)) => { _ = tokio::time::sleep(tokio::time::Duration::from_secs(1)) => {
println!("Job {i} done"); println!("Job {i} done");
Ok(()) Ok(())
} }
// If we receive cancel we close
_ = cancel_token.cancelled() => { _ = cancel_token.cancelled() => {
println!("Job {i} cancelled"); println!("Job {i} cancelled");
Ok(()) Ok(())
@@ -95,5 +101,9 @@ async fn main() -> anyhow::Result<()> {
Dual-licensed under **MIT** or **Apache-2.0**. Dual-licensed under **MIT** or **Apache-2.0**.
See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE) for details. 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: git.front.kjuulh.io/kjuulh/noworkers.

View File

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