Mix async code with CPU-heavy thread pools using Tokio + Rayon

Overview

tokio-rayon

Mix async code with CPU-heavy thread pools using Tokio + Rayon

Documentation Build status Test coverage
crates.io Downloads Rust version
MIT license

Resources

TL;DR

Sometimes, you're doing async stuff, and you also need to do CPU-heavy stuff. This library will help!

let nft = tokio_rayon::spawn_async(|| {
  do_some_crypto_stuff()
}).await?;

assert_eq!(nft, ExpensiveNft);
You might also like...
Rc version `tokio-rs/bytes`

RcBytes The aim for this crate is to implement a Rc version bytes, which means that the structs in this crate does not implement the Sync and Send. Th

Alternative StreamMap fork of tokio-stream

streammap-ext This is a fork of StreamMap from tokio-stream crate. The only difference between the implementations is that this version of StreamMap n

Async executor for WebAssembly

There are a number of async task executors available in Rust's ecosystem. However, most (if not all?) of them rely on primitives that might not be available or optimal for WebAssembly deployment at the time.

The feature-rich, portable async channel library

The feature-rich, portable async channel library crates.io docs.rs Why use Postage? Includes a rich set of channels. | barrier | broadcast | dispa

Another Async IO Framework based on io_uring

kbio, the Async IO Framework based on io_uring, is used in KuiBaDB to implement async io. Features Support multi-threading concurrent task submission.

async-alloc-counter measures max allocations in a future invocation

async-alloc-counter measures max allocations in a future invocation see examples/ for usage This allocator can be used as follows: use async_alloc_cou

Golang like WaitGroup implementation for sync/async Rust.

wg Golang like WaitGroup implementation for sync/async Rust.

single file, std only, async Rust executor

whorl - A single file, std only, async Rust executor whorl was created to teach you how async executors work in Rust. It is not the fastest executor n

BPF library for Async Rust, complementary for libbpf-rs.

libbpf-async A library for writing BPF programs in Async Rust, complementary for libbpf-rs, Rust wrapper for libbpf. Currently, this provides Async-fr

Comments
  • v2: Propagate panics, add `AsyncHandle`

    v2: Propagate panics, add `AsyncHandle`

    Code changes

    • Use std::panic to propagate panics from the thread pool into the async context, rather than triggering the Rayon panic handler.
    • Add AsyncRayonHandle type that implements Future, which makes the async-trait crate unnecessary.
    • Bypass Tokio RecvError. We control the Sender, so it should never be dropped too early.
    • Remove prelude module.
    • Seal AsyncThreadPool trait.

    Repository changes

    • Update CI settings to support Rust 1.45.0 and up.
    • Update Codecov settings.
    • Add changelog.
    • Update README.
    opened by andybarron 5
  • Comparison to the `impedance` crate, and also consider propagating panic's

    Comparison to the `impedance` crate, and also consider propagating panic's

    I have been working on a library that is supposed to make it easier to work with blocking code while writing async programs: https://docs.rs/impedance/0.3.0/impedance/

    One such module in this library is the rayon one. Currently, this provides a function that lets you correctly use a 'static rayon ParallelIterator in an asynchronous fashion: https://docs.rs/impedance/0.3.0/impedance/rayon/fn.par_iter.html

    This code is very similar to the way tokio-rayon works (as they both use the suggestion from the tokio readme itself: use a oneshot), but with one difference: impedance catches panic's and allows users to unpack and resume unwinds.

    Today, I was looking into adding a more complete api to impedance that lets users easily use rayon ParallelIterators that contain references (https://github.com/guswynn/impedance/blob/setup/src/rayon.rs#L50-L57), but I hit a snag: https://github.com/rust-lang/rust/issues/70263#issuecomment-869913178 that may not be easy to resolve. Therefore, I an interested in offering a more general api that would be the same as tokio_rayon::spawn, except catching panics. This would let users write things like:

    spawn(
         vec,
        |v| v.par_iter(|reference| ...).collect(),
    )
    

    My understanding is that the MIT licenses on our projects are very permissive so this shouldn't be a licensing problem, but I wanted to let you know of the similarities between your crate and this (planned) section of my crate and see if you have any objections to me offering such an api. Also, if tokio-rayon in the future exports an API that exposes panics to the caller, then it might be possible to have impedance just re-export, and that may be something I am interested in!

    opened by guswynn 3
Owner
Andy Barron
I came here to build cool stuff and chew bubblegum... and I'm all out of gum.
Andy Barron
Graceful shutdown util for Rust projects using the Tokio Async runtime.

Shutdown management for graceful shutdown of tokio applications. Guard creating and usage is lock-free and the crate only locks when: the shutdown sig

Plabayo 54 Sep 29, 2023
Async Rust cron scheduler running on Tokio.

Grizzly Cron Scheduler A simple and easy to use scheduler, built on top of Tokio, that allows you to schedule async tasks using cron expressions (with

Ivan Brko 4 Feb 27, 2024
Fast, initializable, and thread safe static variables

tagged_cell Fast, initializable, and thread safe static variables Overview Borrows the excellent ZST based tagging implementation (linked below) to gu

David Schwarz 8 Nov 10, 2022
Ever wanted to torture your CPU by generating every image possible?

dumpsterfire Ever wanted to torture your CPU by generating every image possible? Well, now you can! This thing is worse than mining Bitcoin, since the

null 2 Jun 14, 2022
🐝🦀🔥 An ebpf based CPU profiler written in Rust

profile-bee ?? ?? ?? Profile Bee is an eBPF based CPU profiler written in Rust for performance and efficiency. Aya is used for building the BPF progra

Joshua Koo 5 Dec 16, 2022
Provides utility functions to perform a graceful shutdown on an tokio-rs based service

tokio-graceful-shutdown IMPORTANT: This crate is in an early stage and not ready for production. This crate provides utility functions to perform a gr

null 61 Jan 8, 2023
An asynchronous IO utilities crate powered by tokio.

An asynchronous IO utilities crate powered by tokio.

Harry 2 Aug 18, 2022
dark-std an Implementation of asynchronous containers build on tokio

dark-std dark-std is an Implementation of asynchronous containers build on tokio. It uses a read-write separation design borrowed from Golang SyncHash

darkrpc 4 Dec 13, 2022
Pure Rust library for Apache ZooKeeper built on tokio

zookeeper-async Async Zookeeper client written 100% in Rust, based on tokio. This library is intended to be equivalent with the official (low-level) Z

Kamil Rojewski 16 Dec 16, 2022
Thin wrapper around [`tokio::process`] to make it streamable

This library provide ProcessExt to create your own custom process

null 4 Jun 25, 2022