Expand description
A safe Rust async runtime.
§Features
forbid(unsafe_code)- Depends only on
stdat runtime - Good test coverage (>80%)
- Good performance
§Limitations
- No
fsmodule yet. async-fs is a fast async networking library that works well with Safina. It contains some unsafe code. - The
netmodule has poor performance. async-net is a fast async networking library that works well with Safina. It contains some unsafe code.
§Benchmark
% ulimit -n 100000 && cargo run --release --package bench
safina tokio
schedule 554ns 635ns
yield 1150ns 729ns
sleep 814ns 842ns
mutex 14201ns 14768ns
oneshot 2510ns 810ns
channel 2526ns 863ns
tcp_echo 28502ns 8187ns§Examples
use std::sync::Arc;
use safina::executor::Executor;
let executor: Arc<Executor> = Arc::default();
let (sender, receiver) = std::sync::mpsc::channel();
executor.spawn(async move {
sender.send(()).unwrap();
});
receiver.recv().unwrap();let result = safina::executor::block_on(async {
prepare_request().await?;
execute_request().await
})?;§Alternatives
- smol
- Popular
- Contains some
unsafecode
- async-std
- Very popular
- Contains generous amounts of
unsafecode
- futures
- Very popular
- Contains generous amounts of
unsafecode
- tokio
- Very popular
- Fast
- Internally extremely complicated
- Full of
unsafecode
- bastion
- Generous amounts of
unsafecode
- Generous amounts of
nostd_async
§Cargo Geiger Safety Report
§Changelog
Changelog
- v0.7.1 2025-07-01
- Add
yield_once()
- Add
- v0.7.0 2025-06-30
- Require Rust 2024 edition.
- Add
OptionAb::into_a, etc. - Threadpool queue is now unbounded, removed
TryScheduleError::QueueFull. SyncSenderno longer requiresClone.- After Executor drops, silently discard new tasks and don’t panic.
- Add
Executor::get_thread_executor_weak.
- v0.6.0 2024-11-02 - Simplify
ExecutorBuilder. - v0.5.0 2024-10-27 - Add
ExecutorBuilderand simplifyExecutorconstructors. - v0.4.1 2024-10-27 - Improve
async_test:- Make
async_testa default feature so it shows up in docs.rs. - Timeout after 5s.
- Override timeout with
#[async_test(timeout_sec = 1)]. - Support
#[should_panic]and other test modifier macros. - Stop adding
_to the end of the test name.
- Make
- v0.4.0 2024-10-26 - Merge crates into this crate.
- v0.3.3 - Update docs.
- v0.3.2 - Add
threadpoolmodule. - v0.3.1
- Add
sync_channelandSyncSender. - Add
Receiver::async_recvto let users await without writing ugly(&mut receiver).await. - Remove
Receiver::blockingand addtry_recv,recv, etc.
- Add
- v0.3.0
- Move structs into sub-modules.
- Replace
Promisewithoneshot,OneSender, andReceiverthat supports async and blocking reads. schedule_blockingto return newsync::Receiver.
- v0.2.1 - Update docs.
- v0.2.0
Executor::newandExecutor::with_nameto returnResult.ThreadPool::newto returnResult.ThreadPool::try_scheduleto return an error when it fails to restart panicked threads.ThreadPool::scheduleto handle failure starting replacement threads.
- v0.1.10 -
block_onfunctions to take futures that are notSend. - v0.1.9 - Use
once_cellby default. - v0.1.8 - Support stable with rust 1.51 and
once_cell. - v0.1.7 - Add safina-net
- v0.1.6 - Use safina-executor v0.1.3 API
- v0.1.5 - Add
safina::sync::Mutex - v0.1.4 - Upgrade to new safina-executor version which removes need for
Box::pin. - v0.1.3 - Update docs
- v0.1.2 - Renamed
safinacrate tosafina-executor. Added newsafinacrate with re-exports, examples, and integration tests. - v0.1.1 - Add badges to readme
- v0.1.0 - First published version
§TO DO
- Add
initfunction that makes an executor and starts the timer thread. - Add an
#[async_main]macro safina::sync::unbounded_channel()- Make [
safina::sync::MutexGuard] Send.
License: Apache-2.0
Modules§
- executor
- net
- A safe Rust library for network communication.
- select
- Await multiple futures and get the value of the first one that completes.
- sync
- Structs for sharing or sending data between async tasks and threads.
- threadpool
- A thread pool.
- timer
- Provides async
sleep_forandsleep_untilfunctions. - util
Attribute Macros§
- async_
test - A macro for running
async fntests.