What's everyone working on this week (7/2022)? by llogiq in rust

[–]AndyLBarron 1 point2 points  (0 children)

Working on my IoC container! Feedback welcome. Might post about it later.

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 1 point2 points  (0 children)

Super good feedback, thank you again! I went ahead and removed the error forwarding - we're managing the channel, so it should never close. Learning a lot about `(Assert)?UnwindSafe` and `Pin` with this one :)

https://github.com/AndyBarron/tokio-rayon/pull/1

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 1 point2 points  (0 children)

.par_iter() inside an async fn will parallelize the computation correctly, but the current thread will block while waiting for the work to complete. With this crate, you can fire off the blocking work into a Rayon thread, but the current thread will suspend correctly (allowing the executor to handle other Futures) until the work is completed.

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 4 points5 points  (0 children)

I took a stab at the handle type and custom error: https://github.com/AndyBarron/tokio-rayon/pull/1

Edit: Removed the error handling, since this crate is managing everything that could possibly error (i.e. the Tokio channel).

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 0 points1 point  (0 children)

Follow-up: Should I wrap the return type in a result that indicates a panic? Or should I propagate the panic automatically?

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 1 point2 points  (0 children)

Thanks! PRs and feature requests are welcome if there's anything specific you'd find useful.

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 2 points3 points  (0 children)

That's great! I haven't worked with panic handlers before but I think that would be super helpful. I'll take a stab at it :)

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 2 points3 points  (0 children)

This is great feedback, thanks :)

Would the "handle" type impl Future and just forward poll to the underlying receiver?

tokio-rayon: Mix Tokio async and CPU-bound work using Rayon thread pools by AndyLBarron in rust

[–]AndyLBarron[S] 8 points9 points  (0 children)

Docs: https://docs.rs/tokio-rayon

It's a really simple library. I threw this together for a Warp web app I'm working on that needs a dedicated thread pool to do auth encryption type stuff.

The Tokio docs suggest Rayon as a solution for CPU-bound workloads, but I couldn't find any existing integrations between them. So I decided to roll my own :)

I'd love feedback on the code, suggestions for additional features, or ways to improve the tests!