MCPcopy Index your code
hub / github.com/BVE-Reborn/switchyard

github.com/BVE-Reborn/switchyard @v0.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.1 ↗ · + Follow
72 symbols 163 edges 13 files 17 documented · 24% updated 7d agov0.3.1 · 2025-04-26★ 741 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

switchyard

GitHub Workflow Status Crates.io Documentation License

Real-time compute-focused async executor with job pools, thread-local data, and priorities.

Example

use switchyard::Switchyard;
use switchyard::threads::{thread_info, one_to_one};
// Create a new switchyard without thread local data
let yard = Switchyard::new(one_to_one(thread_info(), Some("thread-name")), ||()).unwrap();

// Spawn a task on priority 10 and get a JoinHandle
let handle = yard.spawn(10, async move { 5 + 5 });
// Spawn a lower priority task
let handle2 = yard.spawn(0, async move { 2 + 2 });

// Wait on the results
assert_eq!(handle.await + handle2.await, 14);

How Switchyard is Different

Switchyard is different from other existing async executors, focusing on situations where precise control of threads and execution order is needed. One such situation is using task parallelism to parallelize a compute workload.

Priorites

Each task has a priority and tasks are ran in order from high priority to low priority.

// Spawn task with lowest priority.
yard.spawn(0, async move { /* ... */ });
// Spawn task with higher priority. If both tasks are waiting, this one will run first.
yard.spawn(10, async move { /* ... */ });

Thread Local Data

Each yard has some thread local data that can be accessed using spawn_local. Both the thread local data and the future generated by the async function passed to spawn_local may be !Send and !Sync. The future will only be resumed on the thread that created it.

// Create yard with thread local data. The data is !Sync.
let yard = Switchyard::new(one_to_one(thread_info(), Some("thread-name")), || Cell::new(42)).unwrap();

// Spawn task that uses thread local data. Each running thread will get their own copy.
yard.spawn_local(0, |data| async move { data.set(10) });

MSRV

1.65

Future MSRV bumps will be breaking changes.

License: MIT OR Apache-2.0 OR Zlib

Core symbols most depended-on inside this repo

spawn
called by 17
src/lib.rs
single_thread
called by 15
src/threads.rs
to_address
called by 9
src/task.rs
wait_for_idle
called by 5
src/lib.rs
notify_one
called by 4
src/lib.rs
spawn_local
called by 4
src/lib.rs
finish
called by 4
src/lib.rs
thread_info
called by 3
src/threads.rs

Shape

Method 26
Function 24
Class 19
Enum 3

Languages

Rust100%

Modules by API surface

src/lib.rs19 symbols
src/task.rs16 symbols
tests/simple.rs7 symbols
src/util.rs6 symbols
src/threads.rs6 symbols
tests/ub.rs5 symbols
tests/panic.rs4 symbols
tests/interface.rs2 symbols
src/error.rs2 symbols
benches/scheduling.rs2 symbols
tests/threads.rs1 symbols
src/worker.rs1 symbols

For agents

$ claude mcp add switchyard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact