single file, std only, async Rust executor

Related tags

Utilities rust async
Overview

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 nor is it's API perfect, but it will teach you about them and how they work and where to get started if you wanted to make your own. It's written in a literate programming style such that reading it from beginning to end tells you a story about how it works or you can read parts of it in chunks depending on what you want to get out of it.

You can read it all online here on GitHub or you can clone the repo yourself and open up src/lib.rs to read through it in your favorite text editor or play around with it and change things. All of the code is licensed under the MIT License so you're mostly free to do with it as you wish. If you want to make the next tokio or just make something for fun you can do that.

If you just want to see it in action an example test program is included as part of the file. You can see it's output by just running:

cargo test -- --nocapture

Which should look something like this:

whorl on  main [!⇡] is 📦 v0.1.0 via 🦀 v1.56.0 took 10s
❯ cargo test -- --nocapture
   Compiling whorl v0.1.0 (/home/michael/whorl)
    Finished test [unoptimized + debuginfo] target(s) in 0.47s
     Running unittests (target/debug/deps/whorl-6d670ffb5bb225ca)

running 1 test
Begin Asynchronous Execution
Blocking Function Polled To Completion
Spawned Fn #00: Start 1635276666
Spawned Fn #01: Start 1635276666
Spawned Fn #02: Start 1635276666
Spawned Fn #03: Start 1635276666
Spawned Fn #04: Start 1635276666
Spawned Fn #00: Ended 1635276669
Spawned Fn #02: Ended 1635276669
Spawned Fn #03: Ended 1635276669
Spawned Fn #01: Ended 1635276670
Spawned Fn #00: Inner 1635276671
Spawned Fn #03: Inner 1635276674
Spawned Fn #04: Ended 1635276675
Spawned Fn #02: Inner 1635276675
Spawned Fn #01: Inner 1635276678
Spawned Fn #04: Inner 1635276678
End of Asynchronous Execution
test library_test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 23.00s

   Doc-tests whorl

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

This was originally created for my monthly newsletter. You can find that post in particular here or you can sign up for it here.

You might also like...
A tool that transforms an IMVU badge canvas into a single cohesive image.

IMVU Badge Canvas Image Generator This tool fetches an IMVU user's badge canvas and creates a single unified image representation of it. Instead of ha

Scope-based single and multithreaded profiling.
Scope-based single and multithreaded profiling.

Profi A simple profiler for single and multithreaded applications. Record the time it takes for a scope to end and print the timings when the program

Golang like WaitGroup implementation for sync/async Rust.

wg Golang like WaitGroup implementation for sync/async Rust.

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

Rust library for one-time async initialization

async-lazy An async version of once_cell::sync::Lazy, std::sync::OnceLock or lazy_static. Uses tokio's sychronization primitives. This crate offers an

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

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

Develop an async runtime like thing in Rust for educational purpose.

How-not-to-async-rs Develop an async runtime like thing in Rust for educational purpose. What this is not This is not going to be a blog post explaini

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

Comments
  • Fix typos and punctuation issues

    Fix typos and punctuation issues

    Thanks for the interesting read; I certainly learned a lot!

    While reading, I found a few typos and grammatical issues. All of these points are very minor, and I have tried not to change the wording unless necessary.

    You'll note that I changed some occurrences of "it's", "get's", and "let's" to "its", "gets" and "lets" respectively. At the risk of being nitpicky, this looked like a common error throughout the writing, so here is an article, which might help explain the difference.

    Other than that the text is great and I'm looking forward to a print version. 😉

    opened by mre 2
  • Fix typo

    Fix typo

    I do not think that there should be uncommenting because the following lines are not commented. Should be there commenting instead?

    Anyway, thank you for your awesome example!

    opened by wutchzone 1
  • Change AtomicBool to bool

    Change AtomicBool to bool

    In previous iterations of whorl we needed an AtomicBool, but since we wrap a Task in an Arc we don't actually need it since we never change the value either. The Task either blocks or does not and that does not change at all. We change to a normal bool and remove any phrasing related to it being an AtomicBool.

    Closes #4

    opened by mgattozzi 0
Owner
Michael Gattozzi
Rustacean 🦀"a bad programmer" according to the Orange Site, he/him
Michael Gattozzi
Rust library to scan files and expand multi-file crates source code as a single tree

syn-file-expand This library allows you to load full source code of multi-file crates into a single syn::File. Features: Based on syn crate. Handling

Vitaly Shukela 11 Jul 27, 2022
no-std no-alloc Rust protobufs.

noproto No-std, no-alloc protocol buffers (protobuf) implementation in Rust, for embedded systems. Optimized for binary size and memory usage, not for

null 13 Jun 21, 2023
Debug2 is a pretty printing crate based on std::fmt

debug2 is a pretty printing crate based on std::fmt Why not just use Debug The Debug trait is good, but the problem is it is not very good at n

Nixon Enraght-Moony 18 Jun 23, 2022
Extent - replacement for std::ops::{Range,RangeInclusive}

extent This is an alternative to std::ops::{Range,RangeInclusive}, avoiding the quirks of those types (non-Copy, inability to produce empty inclusive

Graydon Hoare 33 Sep 27, 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
This crate allows you to safely initialize Dynamically Sized Types (DST) using only safe Rust.

This crate allows you to safely initialize Dynamically Sized Types (DST) using only safe Rust.

Christofer Nolander 11 Dec 22, 2022
Detect if code is running inside a virtual machine (x86 and x86-64 only).

inside-vm Detect if code is running inside a virtual machine. Only works on x86 and x86-64. How does it work Measure average cpu cycles when calling c

null 34 Oct 3, 2022
A self-contained, single-binary Rust and Leptos application for remote Wake-on-LAN

Remote Wake-on-LAN with Rust and Leptos A self-contained, single-binary Rust and Leptos application serving a web interface to wake another device on

Valentin Bersier 6 Jan 28, 2023
An opinionated Rust library for interacting with AWS DynamoDB single-table designs.

Modyne An opinionated library for interacting with AWS DynamoDB single-table designs. † Motive Modyne follows the precepts laid out for effective sing

Marcus Griep 14 Jun 8, 2023
DynamoDB library for single-table design in Rust

A DynamoDB abstraction for Rust Deez is a DynamoDB abstraction for implementing Single Table Design easily, inspired by ElectroDB. Getting Started Def

null 10 Jul 2, 2023