10 Commits

Author SHA1 Message Date
8121bf7985 chore(release): v0.0.4 (#4)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.0.4

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: #4
2025-08-08 22:01:35 +02:00
49b931775c chore: Configure Renovate (#3)
All checks were successful
continuous-integration/drone/push Build is passing
Add renovate.json

Reviewed-on: #3
2025-08-08 22:00:58 +02:00
5ab54585c0 feat: update noworkers
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2025-08-08 21:58:33 +02:00
119fb101cf feat: add sys limit
Some checks failed
continuous-integration/drone/push Build is failing
2025-08-01 14:42:36 +02:00
177820f3c3 docs: clarify usage
Some checks failed
continuous-integration/drone/push Build is failing
2025-07-01 16:08:33 +02:00
3fc9c3143f docs: set private url 2025-07-01 16:03:34 +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
8 changed files with 59 additions and 15 deletions

View File

@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.0.4] - 2025-08-08
### Other
- Configure Renovate (#3)
Add renovate.json
## [0.0.1] - 2025-07-01
### Added

2
Cargo.lock generated
View File

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

View File

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

View File

@@ -5,6 +5,12 @@ 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)`.
@@ -25,33 +31,39 @@ Then in your code:
```rust
use noworkers::Workers;
use tokio_util::sync::CancellationToken;
```
## Quick Example
```rust,no_run
```rust
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();
workers
.with_limit(5)
.with_cancel(&CancellationToken::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
});
// 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 {
// 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! {
// 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(())
@@ -95,5 +107,9 @@ 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.kjuulh.io/kjuulh/noworkers.

View File

@@ -3,8 +3,8 @@ name = "noworkers"
edition = "2024"
readme = "../../README.md"
version.workspace = true
license = "MIT or APACHE"
repository = "https://git.front.kjuulh.io/kjuulh/noworkers"
license.workspace = true
repository = "https://git.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)"

View File

@@ -3,6 +3,24 @@ use std::{future::Future, sync::Arc};
use tokio::{sync::Mutex, task::JoinHandle};
use tokio_util::sync::CancellationToken;
pub mod extensions {
use crate::Workers;
pub trait WithSysLimitCpus {
fn with_limit_to_system_cpus(&mut self) -> &mut Self;
}
impl WithSysLimitCpus for Workers {
fn with_limit_to_system_cpus(&mut self) -> &mut Self {
self.with_limit(
std::thread::available_parallelism()
.expect("to be able to get system cpu info")
.into(),
)
}
}
}
type ErrChan = Arc<
Mutex<(
Option<tokio::sync::oneshot::Sender<anyhow::Error>>,

View File

@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
# yaml-language-server: $schema=https://git.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-lib-plan.git"
base: "git@git.kjuulh.io:kjuulh/cuddle-rust-lib-plan.git"
vars:
service: "noworkers"
@@ -12,6 +12,6 @@ please:
repository: "noworkers"
branch: main
settings:
api_url: "https://git.front.kjuulh.io"
api_url: "https://git.kjuulh.io"
actions:
rust:

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}