Document the behaviour of the `select!` macro
This commit is contained in:
parent
1c87372b03
commit
829a6f11c5
|
@ -143,6 +143,7 @@ where
|
||||||
},
|
},
|
||||||
Some(mut sleep) => {
|
Some(mut sleep) => {
|
||||||
// Wait on either a new message or the batch timer.
|
// Wait on either a new message or the batch timer.
|
||||||
|
// If both are ready, select! chooses one of them at random.
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
maybe_msg = self.rx.recv() => match maybe_msg {
|
maybe_msg = self.rx.recv() => match maybe_msg {
|
||||||
Some(msg) => {
|
Some(msg) => {
|
||||||
|
|
|
@ -223,6 +223,8 @@ where
|
||||||
.in_current_span();
|
.in_current_span();
|
||||||
|
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
|
// TODO: if the verifier and cancel are both ready, which should we
|
||||||
|
// prefer? (Currently, select! chooses one at random.)
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = &mut cancel_rx => {
|
_ = &mut cancel_rx => {
|
||||||
tracing::trace!("task cancelled prior to completion");
|
tracing::trace!("task cancelled prior to completion");
|
||||||
|
|
|
@ -149,6 +149,8 @@ where
|
||||||
let mut verifier = self.verifier.clone();
|
let mut verifier = self.verifier.clone();
|
||||||
let task = tokio::spawn(
|
let task = tokio::spawn(
|
||||||
async move {
|
async move {
|
||||||
|
// TODO: if the verifier and cancel are both ready, which should
|
||||||
|
// we prefer? (Currently, select! chooses one at random.)
|
||||||
let rsp = tokio::select! {
|
let rsp = tokio::select! {
|
||||||
_ = &mut cancel_rx => {
|
_ = &mut cancel_rx => {
|
||||||
tracing::trace!("task cancelled prior to download completion");
|
tracing::trace!("task cancelled prior to download completion");
|
||||||
|
@ -169,6 +171,8 @@ where
|
||||||
metrics::counter!("sync.downloaded.block.count", 1);
|
metrics::counter!("sync.downloaded.block.count", 1);
|
||||||
|
|
||||||
let rsp = verifier.ready_and().await?.call(block);
|
let rsp = verifier.ready_and().await?.call(block);
|
||||||
|
// TODO: if the verifier and cancel are both ready, which should
|
||||||
|
// we prefer? (Currently, select! chooses one at random.)
|
||||||
let verification = tokio::select! {
|
let verification = tokio::select! {
|
||||||
_ = &mut cancel_rx => {
|
_ = &mut cancel_rx => {
|
||||||
tracing::trace!("task cancelled prior to verification");
|
tracing::trace!("task cancelled prior to verification");
|
||||||
|
|
|
@ -46,6 +46,8 @@ pub(crate) trait RuntimeRun {
|
||||||
impl RuntimeRun for Runtime {
|
impl RuntimeRun for Runtime {
|
||||||
fn run(&mut self, fut: impl Future<Output = Result<(), Report>>) {
|
fn run(&mut self, fut: impl Future<Output = Result<(), Report>>) {
|
||||||
let result = self.block_on(async move {
|
let result = self.block_on(async move {
|
||||||
|
// If the run task and shutdown are both ready, select! chooses
|
||||||
|
// one of them at random.
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
result = fut => result,
|
result = fut => result,
|
||||||
_ = shutdown() => Ok(()),
|
_ = shutdown() => Ok(()),
|
||||||
|
@ -68,6 +70,7 @@ mod imp {
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
pub(super) async fn shutdown() {
|
pub(super) async fn shutdown() {
|
||||||
|
// If both signals are received, select! chooses one of them at random.
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
// SIGINT - Terminal interrupt signal. Typically generated by shells in response to Ctrl-C.
|
// SIGINT - Terminal interrupt signal. Typically generated by shells in response to Ctrl-C.
|
||||||
() = sig(SignalKind::interrupt(), "SIGINT") => {}
|
() = sig(SignalKind::interrupt(), "SIGINT") => {}
|
||||||
|
|
Loading…
Reference in New Issue