You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use futures::Future;use std::{mem::swap, pin::Pin, task::Poll, time::Duration};use tokio::{macros::support::poll_fn, time::sleep};#[tokio::main]asyncfnmain(){letmut sleep1 = sleep(Duration::from_secs(1));letmut sleep2 = sleep(Duration::from_secs(1));{// let's use `sleep1` pinned exactly _once_letmut sleep1 = unsafe{Pin::new_unchecked(&mut sleep1)};// this creates a future whose poll method is the closure argumentpoll_fn(|cx| {// we poll `sleep1` once, throwing away the result...let _ = sleep1.as_mut().poll(cx);// ...and resolve immediatelyPoll::Ready(())}).await;}// then, let's use `sleep1` unpinned:swap(&mut sleep1,&mut sleep2);// by this point, `sleep1` has switched places with `sleep2`// finally, let's await both sleep1 and sleep2
sleep1.await;
sleep2.await;}
Results in:
thread 'tokio-runtime-worker' panicked at 'assertion failed: cur_state < STATE_MIN_VALUE', /home/amos/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.4.0/src/time/driver/entry.rs:174:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
But the panic is from a debug assert: debug_assert!(cur_state < STATE_MIN_VALUE);, so in --release mode, nothing happens.
Additionally, the panic message is poor. We should:
a) panic in release mode as well
b) have a better error message describing the problem.
The text was updated successfully, but these errors were encountered:
Darksonn
removed
E-help-wanted
Call for participation: Help is requested to fix this issue.
E-easy
Call for participation: Experience needed to fix: Easy / not much
labels
Jan 30, 2023
From: https://fasterthanli.me/articles/pin-and-suffering (search for
debug_assert!
).Results in:
But the panic is from a debug assert:
debug_assert!(cur_state < STATE_MIN_VALUE);
, so in--release
mode, nothing happens.Additionally, the panic message is poor. We should:
a) panic in release mode as well
b) have a better error message describing the problem.
The text was updated successfully, but these errors were encountered: