mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-07 05:05:32 +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()) {
|
||||
(Some("client"), None) => client::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 name = match lines.next().await {
|
||||
None => Err("peer disconnected immediately")?,
|
||||
None => return Err("peer disconnected immediately".into()),
|
||||
Some(line) => line?,
|
||||
};
|
||||
let (_shutdown_sender, shutdown_receiver) = mpsc::unbounded::<Void>();
|
||||
|
|
|
@ -115,6 +115,7 @@ fn next_interval(prev: Instant, now: Instant, interval: Duration) -> Instant {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::next_interval;
|
||||
use std::cmp::Ordering;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
struct Timeline(Instant);
|
||||
|
@ -138,12 +139,10 @@ mod test {
|
|||
// The math around Instant/Duration isn't 100% precise due to rounding
|
||||
// errors, see #249 for more info
|
||||
fn almost_eq(a: Instant, b: Instant) -> bool {
|
||||
if a == b {
|
||||
true
|
||||
} else if a > b {
|
||||
a - b < Duration::from_millis(1)
|
||||
} else {
|
||||
b - a < Duration::from_millis(1)
|
||||
match a.cmp(&b) {
|
||||
Ordering::Equal => true,
|
||||
Ordering::Greater => a - b < Duration::from_millis(1),
|
||||
Ordering::Less => b - a < Duration::from_millis(1),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,6 +154,7 @@ where
|
|||
|
||||
fn vtable() -> &'static RawWakerVTable {
|
||||
unsafe fn clone_raw(ptr: *const ()) -> RawWaker {
|
||||
#![allow(clippy::redundant_clone)]
|
||||
let arc = ManuallyDrop::new(Arc::from_raw(ptr as *const Parker));
|
||||
mem::forget(arc.clone());
|
||||
RawWaker::new(ptr, vtable())
|
||||
|
|
|
@ -4,6 +4,7 @@ use async_std::task;
|
|||
|
||||
#[test]
|
||||
fn test_buffered_writer() {
|
||||
#![allow(clippy::cognitive_complexity)]
|
||||
task::block_on(async {
|
||||
let inner = Vec::new();
|
||||
let mut writer = BufWriter::with_capacity(2, inner);
|
||||
|
|
|
@ -37,6 +37,7 @@ fn capacity() {
|
|||
|
||||
#[test]
|
||||
fn len_empty_full() {
|
||||
#![allow(clippy::cognitive_complexity)]
|
||||
task::block_on(async {
|
||||
let (s, r) = channel(2);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use futures::channel::mpsc;
|
|||
/// Generates a random number in `0..n`.
|
||||
pub fn random(n: u32) -> u32 {
|
||||
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| {
|
||||
|
|
Loading…
Reference in a new issue