mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-31 13:36:41 +00:00
commit
c2a084ed4a
7 changed files with 11 additions and 9 deletions
|
@ -8,6 +8,6 @@ fn main() -> Result<()> {
|
||||||
match (args.nth(1).as_ref().map(String::as_str), args.next()) {
|
match (args.nth(1).as_ref().map(String::as_str), args.next()) {
|
||||||
(Some("client"), None) => client::main(),
|
(Some("client"), None) => client::main(),
|
||||||
(Some("server"), None) => server::main(),
|
(Some("server"), None) => server::main(),
|
||||||
_ => Err("Usage: a-chat [client|server]")?,
|
_ => Err("Usage: a-chat [client|server]".into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ async fn connection_loop(mut broker: Sender<Event>, stream: TcpStream) -> Result
|
||||||
let mut lines = reader.lines();
|
let mut lines = reader.lines();
|
||||||
|
|
||||||
let name = match lines.next().await {
|
let name = match lines.next().await {
|
||||||
None => Err("peer disconnected immediately")?,
|
None => return Err("peer disconnected immediately".into()),
|
||||||
Some(line) => line?,
|
Some(line) => line?,
|
||||||
};
|
};
|
||||||
let (_shutdown_sender, shutdown_receiver) = mpsc::unbounded::<Void>();
|
let (_shutdown_sender, shutdown_receiver) = mpsc::unbounded::<Void>();
|
||||||
|
|
|
@ -115,6 +115,7 @@ fn next_interval(prev: Instant, now: Instant, interval: Duration) -> Instant {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::next_interval;
|
use super::next_interval;
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
struct Timeline(Instant);
|
struct Timeline(Instant);
|
||||||
|
@ -138,12 +139,10 @@ mod test {
|
||||||
// The math around Instant/Duration isn't 100% precise due to rounding
|
// The math around Instant/Duration isn't 100% precise due to rounding
|
||||||
// errors, see #249 for more info
|
// errors, see #249 for more info
|
||||||
fn almost_eq(a: Instant, b: Instant) -> bool {
|
fn almost_eq(a: Instant, b: Instant) -> bool {
|
||||||
if a == b {
|
match a.cmp(&b) {
|
||||||
true
|
Ordering::Equal => true,
|
||||||
} else if a > b {
|
Ordering::Greater => a - b < Duration::from_millis(1),
|
||||||
a - b < Duration::from_millis(1)
|
Ordering::Less => b - a < Duration::from_millis(1),
|
||||||
} else {
|
|
||||||
b - a < Duration::from_millis(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,7 @@ where
|
||||||
|
|
||||||
fn vtable() -> &'static RawWakerVTable {
|
fn vtable() -> &'static RawWakerVTable {
|
||||||
unsafe fn clone_raw(ptr: *const ()) -> RawWaker {
|
unsafe fn clone_raw(ptr: *const ()) -> RawWaker {
|
||||||
|
#![allow(clippy::redundant_clone)]
|
||||||
let arc = ManuallyDrop::new(Arc::from_raw(ptr as *const Parker));
|
let arc = ManuallyDrop::new(Arc::from_raw(ptr as *const Parker));
|
||||||
mem::forget(arc.clone());
|
mem::forget(arc.clone());
|
||||||
RawWaker::new(ptr, vtable())
|
RawWaker::new(ptr, vtable())
|
||||||
|
|
|
@ -4,6 +4,7 @@ use async_std::task;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_buffered_writer() {
|
fn test_buffered_writer() {
|
||||||
|
#![allow(clippy::cognitive_complexity)]
|
||||||
task::block_on(async {
|
task::block_on(async {
|
||||||
let inner = Vec::new();
|
let inner = Vec::new();
|
||||||
let mut writer = BufWriter::with_capacity(2, inner);
|
let mut writer = BufWriter::with_capacity(2, inner);
|
||||||
|
|
|
@ -37,6 +37,7 @@ fn capacity() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn len_empty_full() {
|
fn len_empty_full() {
|
||||||
|
#![allow(clippy::cognitive_complexity)]
|
||||||
task::block_on(async {
|
task::block_on(async {
|
||||||
let (s, r) = channel(2);
|
let (s, r) = channel(2);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use futures::channel::mpsc;
|
||||||
/// Generates a random number in `0..n`.
|
/// Generates a random number in `0..n`.
|
||||||
pub fn random(n: u32) -> u32 {
|
pub fn random(n: u32) -> u32 {
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static RNG: Cell<Wrapping<u32>> = Cell::new(Wrapping(1406868647));
|
static RNG: Cell<Wrapping<u32>> = Cell::new(Wrapping(1_406_868_647));
|
||||||
}
|
}
|
||||||
|
|
||||||
RNG.with(|rng| {
|
RNG.with(|rng| {
|
||||||
|
|
Loading…
Reference in a new issue