Skip to content

Commit b1b8b2e

Browse files
committed
restore internal RPC debugging
1 parent 670c657 commit b1b8b2e

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

src/future.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::Result;
2+
use std::{
3+
fmt,
4+
future::Future,
5+
pin::Pin,
6+
task::{Context, Poll},
7+
};
8+
9+
pub(crate) struct InternalFuture(
10+
pub(crate) Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>,
11+
);
12+
13+
impl Future for InternalFuture {
14+
type Output = Result<()>;
15+
16+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
17+
Pin::new(&mut self.0).poll(cx)
18+
}
19+
}
20+
21+
impl fmt::Debug for InternalFuture {
22+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23+
f.debug_tuple("InternalFuture").finish()
24+
}
25+
}

src/internal_rpc.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
channels::Channels,
44
consumer_status::ConsumerStatus,
55
error_holder::ErrorHolder,
6+
future::InternalFuture,
67
heartbeat::Heartbeat,
78
killswitch::KillSwitch,
89
options::{BasicAckOptions, BasicCancelOptions, BasicNackOptions, BasicRejectOptions},
@@ -11,7 +12,7 @@ use crate::{
1112
};
1213
use async_rs::{Runtime, traits::*};
1314
use flume::{Receiver, Sender};
14-
use std::{collections::HashMap, fmt, future::Future, pin::Pin, time::Duration};
15+
use std::{collections::HashMap, fmt, future::Future, time::Duration};
1516
use tracing::trace;
1617

1718
pub(crate) struct InternalRPC<RK: RuntimeKit + Clone + Send + 'static> {
@@ -162,14 +163,14 @@ impl InternalRPCHandle {
162163
}
163164

164165
pub(crate) fn spawn(&self, f: impl Future<Output = Result<()>> + Send + 'static) {
165-
self.send(InternalCommand::Spawn(Box::pin(f)));
166+
self.send(InternalCommand::Spawn(InternalFuture(Box::pin(f))));
166167
}
167168

168169
pub(crate) fn spawn_infallible(&self, f: impl Future<Output = ()> + Send + 'static) {
169-
self.send(InternalCommand::Spawn(Box::pin(async move {
170+
self.spawn(async move {
170171
f.await;
171172
Ok(())
172-
})));
173+
});
173174
}
174175

175176
pub(crate) fn start_channels_recovery(&self) {
@@ -190,7 +191,7 @@ impl InternalRPCHandle {
190191
}
191192

192193
fn send(&self, command: InternalCommand) {
193-
trace!("Queuing internal RPC command"); // FIXME: restore ?command (future is not debug for Spawn)
194+
trace!(?command, "Queuing internal RPC command");
194195
// The only scenario where this can fail if this is the IoLoop already exited
195196
let _ = self.sender.send(Some(command));
196197
self.waker.wake();
@@ -203,6 +204,7 @@ impl fmt::Debug for InternalRPCHandle {
203204
}
204205
}
205206

207+
#[derive(Debug)]
206208
enum InternalCommand {
207209
BasicAck(
208210
ChannelId,
@@ -239,7 +241,7 @@ enum InternalCommand {
239241
SetConnectionClosing,
240242
SetConnectionClosed(Error),
241243
SetConnectionError(Error),
242-
Spawn(Pin<Box<dyn Future<Output = Result<()>> + Send + 'static>>),
244+
Spawn(InternalFuture),
243245
StartChannelsRecovery,
244246
StartHeartbeat(Duration),
245247
}
@@ -310,7 +312,7 @@ impl<RK: RuntimeKit + Clone + Send + 'static> InternalRPC<RK> {
310312
};
311313

312314
while let Ok(Some(command)) = rpc.recv_async().await {
313-
trace!("Handling internal RPC command"); // FIXME: restore ?command (future is not debug for Spawn)
315+
trace!(?command, "Handling internal RPC command");
314316
match command {
315317
BasicAck(channel_id, delivery_tag, options, resolver, error) => {
316318
if !self.channel_ok(channel_id) {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ mod error_handler;
150150
mod error_holder;
151151
mod exchange;
152152
mod frames;
153+
mod future;
153154
mod heartbeat;
154155
mod id_sequence;
155156
mod internal_rpc;

0 commit comments

Comments
 (0)