Skip to content

Commit

Permalink
Make SharedHandleContainer a proper struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
nihohit committed Sep 12, 2024
1 parent 2c99b19 commit 78d53f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions redis/src/aio/multiplexed_connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{new_shared_handle, ConnectionLike, Runtime, SharedHandleContainer, TaskHandle};
use super::{ConnectionLike, Runtime, SharedHandleContainer, TaskHandle};
use crate::aio::{check_resp3, setup_connection};
use crate::cmd::Cmd;
#[cfg(any(feature = "tokio-comp", feature = "async-std-comp"))]
Expand Down Expand Up @@ -517,7 +517,7 @@ impl MultiplexedConnection {
/// This should be called strictly before the multiplexed connection is cloned - that is, before it is returned to the user.
/// Otherwise some clones will be able to kill the backing task, while other clones are still alive.
pub(crate) fn set_task_handle(&mut self, handle: TaskHandle) {
self._task_handle = Some(new_shared_handle(handle));
self._task_handle = Some(SharedHandleContainer::new(handle));
}

/// Sets the time that the multiplexer will wait for responses on operations before failing.
Expand Down
4 changes: 2 additions & 2 deletions redis/src/aio/pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::aio::{new_shared_handle, Runtime};
use crate::aio::Runtime;
use crate::connection::{
check_connection_setup, connection_setup_pipeline, AuthResult, ConnectionSetupComponents,
};
Expand Down Expand Up @@ -371,7 +371,7 @@ impl PubSub {
let (sender, receiver) = unbounded_channel();
let (sink, driver) = PubSubSink::new(codec, sender);
let handle = Runtime::locate().spawn(driver);
let _task_handle = Some(new_shared_handle(handle));
let _task_handle = Some(SharedHandleContainer::new(handle));
let stream = PubSubStream {
receiver,
_task_handle,
Expand Down
11 changes: 8 additions & 3 deletions redis/src/aio/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ impl Drop for HandleContainer {
}
}

pub(crate) type SharedHandleContainer = Arc<HandleContainer>;
#[derive(Clone)]
// we allow dead code here because the container isn't used directly, only in the derived drop.
#[allow(dead_code)]
pub(crate) struct SharedHandleContainer(Arc<HandleContainer>);

pub(crate) fn new_shared_handle(handle: TaskHandle) -> SharedHandleContainer {
Arc::new(HandleContainer::new(handle))
impl SharedHandleContainer {
pub(crate) fn new(handle: TaskHandle) -> Self {
Self(Arc::new(HandleContainer::new(handle)))
}
}

impl Runtime {
Expand Down
6 changes: 2 additions & 4 deletions redis/src/cluster_async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ use std::{
mod request;
mod routing;
use crate::{
aio::{
new_shared_handle, ConnectionLike, MultiplexedConnection, Runtime, SharedHandleContainer,
},
aio::{ConnectionLike, MultiplexedConnection, Runtime, SharedHandleContainer},
cluster::{get_connection_info, slot_cmd},
cluster_client::ClusterParams,
cluster_routing::{
Expand Down Expand Up @@ -128,7 +126,7 @@ where
.forward(inner)
.await;
};
let _task_handle = new_shared_handle(Runtime::locate().spawn(stream));
let _task_handle = SharedHandleContainer::new(Runtime::locate().spawn(stream));

ClusterConnection {
sender,
Expand Down

0 comments on commit 78d53f7

Please sign in to comment.