Merge branch 'master' into example

This commit is contained in:
Stjepan Glavina 2020-04-27 07:32:32 -07:00 committed by GitHub
commit 4f718bac35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 45 deletions

View File

@ -1,3 +1,11 @@
# Version 0.1.2
- Improved internal docs, fixed typos, and more comments
# Version 0.1.1
- Upgrade dependencies
# Version 0.1.0
- Initial release

View File

@ -1,6 +1,6 @@
[package]
name = "smol"
version = "0.1.0"
version = "0.1.2"
authors = ["Stjepan Glavina <stjepang@gmail.com>"]
edition = "2018"
description = "A small and fast async runtime"
@ -19,7 +19,7 @@ readme = "README.md"
# Enable the feature as follows:
# ```
# [dependencies]
# smol = { version = "1", features = ["tokio02"] }
# smol = { version = "0.1", features = ["tokio02"] }
# ```
tokio02 = ["tokio"]
@ -34,7 +34,7 @@ slab = "0.4.2"
socket2 = { version = "0.3.12", features = ["pair", "unix"] }
[dependencies.tokio]
version = "0.2.18"
version = "0.2.19"
default-features = false
features = ["rt-threaded"]
optional = true
@ -45,8 +45,38 @@ nix = "0.17.0"
[target.'cfg(windows)'.dependencies]
wepoll-binding = "2.0.0"
[target.'cfg(windows)'.dev-dependencies]
uds_windows = "0.1.4"
[target.'cfg(target_os = "linux")'.dev-dependencies]
inotify = { version = "0.8.2", default-features = false }
timerfd = "1.1.1"
[dev-dependencies]
anyhow = "1.0.28"
async-h1 = "1.1.2"
async-native-tls = "0.3.3"
async-std = "1.5.0"
async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] }
base64 = "0.12.0"
ctrlc = "3.1.4"
http = "0.2.1"
http-types = "1.2.0"
hyper = { version = "0.13.5", default-features = false, features = ["stream"] }
native-tls = "0.2.4"
num_cpus = "1.13.0"
reqwest = "0.10.4"
scraper = "0.11.0"
signal-hook = "0.1.13"
smol = { path = ".", features = ["tokio02"] }
surf = { version = "2.0.0-alpha.1", default-features = false, features = ["h1-client"] }
tempfile = "3.1.0"
tokio = { version = "0.2.19", default-features = false }
tungstenite = "0.10.1"
url = "2.1.1"
[workspace]
members = [
".",
"examples",
]
]

View File

@ -8,7 +8,8 @@ https://github.com/stjepang/smol)
https://crates.io/crates/smol)
[![Documentation](https://docs.rs/smol/badge.svg)](
https://docs.rs/smol)
[![Chat](https://img.shields.io/discord/701824908866617385.svg?logo=discord)](https://discord.gg/5RxMVnr)
[![Chat](https://img.shields.io/discord/701824908866617385.svg?logo=discord)](
https://discord.gg/x6m5Vvt)
A small and fast async runtime for Rust.
@ -50,7 +51,7 @@ Enable the feature as follows:
```toml
[dependencies]
smol = { version = "1", features = ["tokio02"] }
smol = { version = "0.1", features = ["tokio02"] }
```
[async-std]: https://docs.rs/async-std

View File

@ -7,7 +7,7 @@
//!
//! ```toml
//! [dependencies]
//! smol = { version = "1", features = ["tokio02"] }
//! smol = { version = "0.1", features = ["tokio02"] }
//! ```
//!
//! Run with:

View File

@ -2,8 +2,9 @@
//!
//! This is equivalent to [`futures::executor::block_on()`], but slightly more efficient.
//!
//! The following blog post explains it in detail:
//! - https://stjepang.github.io/2020/01/25/build-your-own-block-on.html
//! The implementation is explained in detail in [*Build your own block_on()*][blog-post].
//!
//! [blog-post]: https://stjepang.github.io/2020/01/25/build-your-own-block-on.html
use std::cell::RefCell;
use std::future::Future;

View File

@ -161,11 +161,11 @@ impl BlockingExecutor {
/// Spawns blocking code onto a thread.
///
/// Note that `blocking!(expr)` is just syntax sugar for
/// `Task::blocking(async move { foo }).await`.
/// `Task::blocking(async move { expr }).await`.
///
/// # Examples
///
/// Read a file to string:
/// Read a file into a string:
///
/// ```no_run
/// use smol::blocking;
@ -289,7 +289,7 @@ pub fn iter<T: Send + 'static>(
///
/// # Examples
///
/// Create an async reader that reads a file:
/// Read from a file:
///
/// ```no_run
/// use futures::prelude::*;
@ -400,7 +400,7 @@ pub fn reader(reader: impl Read + Send + 'static) -> impl AsyncRead + Send + Unp
///
/// # Examples
///
/// Create an async writer that writes into a file:
/// Write into a file:
///
/// ```no_run
/// use futures::prelude::*;

View File

@ -150,7 +150,7 @@ impl Reactor {
self.fire_timers();
}
// Interrupt the reactor.
// Notify that a timer was added.
self.timer_event.notify();
id
@ -242,7 +242,7 @@ impl ReactorLock<'_> {
self.react(false)
}
/// Blocks until at least one event is processed or the syscall is interrupted.
/// Blocks until at least one event is processed.
pub fn wait(&mut self) -> io::Result<()> {
self.react(true)
}
@ -257,39 +257,44 @@ impl ReactorLock<'_> {
Some(Duration::from_secs(0))
};
// Block on I/O events.
match self.reactor.sys.wait(&mut self.events, timeout) {
// The timeout was hit.
Ok(0) => Ok(()),
// At least one I/O event occured.
Ok(_) => {
// Iterate over sources in the event list.
let sources = self.reactor.sources.lock();
for source in self.events.iter().filter_map(|i| sources.get(i)) {
// I/O events may deregister sources, so we need to re-register.
self.reactor.sys.reregister(source.raw, source.key)?;
// Bump the ticker.
let mut wakers = source.wakers.lock();
let tick = source.tick.load(Ordering::Acquire);
source.tick.store(tick.wrapping_add(1), Ordering::Release);
// Wake up tasks waiting on I/O.
for w in wakers.drain(..) {
w.wake();
}
loop {
// Block on I/O events.
match self.reactor.sys.wait(&mut self.events, timeout) {
// The timeout was hit so fire ready timers.
Ok(0) => {
self.reactor.fire_timers();
return Ok(());
}
Ok(())
// At least one I/O event occured.
Ok(_) => {
// Iterate over sources in the event list.
let sources = self.reactor.sources.lock();
for source in self.events.iter().filter_map(|i| sources.get(i)) {
// I/O events may deregister sources, so we need to re-register.
self.reactor.sys.reregister(source.raw, source.key)?;
// Bump the ticker.
let mut wakers = source.wakers.lock();
let tick = source.tick.load(Ordering::Acquire);
source.tick.store(tick.wrapping_add(1), Ordering::Release);
// Wake up tasks waiting on I/O.
for w in wakers.drain(..) {
w.wake();
}
}
return Ok(());
}
// The syscall was interrupted.
Err(err) if err.kind() == io::ErrorKind::Interrupted => continue,
// An actual error occureed.
Err(err) => return Err(err),
}
// The syscall was interrupted.
Err(err) if err.kind() == io::ErrorKind::Interrupted => Ok(()),
// An actual error occureed.
Err(err) => Err(err),
}
}
}