Crate safina[−][src]
A safe Rust async runtime.
Features
forbid(unsafe_code)
- Depends only on
std
- Good test coverage (>92%)
Limitations
- Building on
stable
requires the featureonce_cell
. This usesonce_cell
crate which contains some unsafe code. This is necessary untilstd::lazy::OnceCell
is stable. - Allocates memory. You can avoid allocations by using advanced functions, like
safina_executor::spawn_unpin
. - Not optimized
Documentation
safina_async_test
has an #[async_test]
macro for running async fn
test functions.
Examples
let executor = safina::Executor::default(); let (sender, receiver) = std::sync::mpsc::channel(); executor.spawn(async move { sender.send(()).unwrap(); }); receiver.recv().unwrap();
let result = safina::block_on(async { prepare_request().await?; execute_request().await })?;
Alternatives
smol
- Popular
- Contains generous amounts of
unsafe
code
async-std
- Very popular
- Contains generous amounts of
unsafe
code
futures
- Very popular
- Contains generous amounts of
unsafe
code
tokio
- Very popular
- Fast
- Internally extremely complicated
- Full of
unsafe
bastion
- Generous amounts of
unsafe
code
- Generous amounts of
nostd_async
Changelog
- 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
safina
crate tosafina-executor
. Added newsafina
crate with re-exports, examples, and integration tests. - v0.1.1 - Add badges to readme
- v0.1.0 - First published version
TO DO
- Add an integration test
- Add
init
function that starts worker threads and the timer thread. - Make it work on Rust stable
- Add an
#[async_main]
macro
Release Process
- Edit
Cargo.toml
and bump version number. - Run
./release.sh
Structs
DeadlineExceeded | |
DeadlineFuture | A future wrapper that returns |
Executor | A collection of threads for executing tasks and blocking jobs. |
Mutex | A wrapper around
|
MutexGuard | An RAII
scoped lock of a |
Promise | A Future that resolves when you call |
SelectFuture | A future that polls two futures and returns the value from the one that completes first. |
SleepFuture | A future that completes after the specified time. |
TcpListener | Async wrapper around
|
TcpStream | |
ThreadExecutorGuard | Guard returned by |
TimerThreadNotStarted | Call |
Enums
DeadlineError |
DeadlineError::TimerThreadNotStarted DeadlineError::DeadlineExceeded |
OptionAB | |
OptionABC | |
OptionABCD | |
OptionABCDE |
Functions
block_on | Executes the future on the current thread and returns its result. |
block_on_unpin | Executes the future on the current thread and returns its result. |
get_thread_executor | Gets the |
schedule_blocking | Schedules |
select_ab | Awaits both futures and returns the value from the one that completes first. |
select_abc | Awaits the futures and returns the value from the one that completes first. |
select_abcd | Awaits the futures and returns the value from the one that completes first. |
select_abcde | Awaits the futures and returns the value from the one that completes first. |
set_thread_executor | Sets |
sleep_for | Returns |
sleep_until | Returns after |
spawn | Creates a new task to execute |
spawn_unpin | Creates a new task to execute |
start_timer_thread | Starts the worker thread, if it’s not already started.
You must call this before calling |
with_deadline | Awaits |
with_timeout | Awaits |