Skip to content

Commit

Permalink
chore: remove & disallow unbounded channels
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Feb 7, 2022
1 parent db9ee35 commit 88be98a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
too-many-arguments-threshold = 20
disallowed-methods = [
# unbounded channels are for expert use only
{ path = "tokio::sync::mpsc::unbounded", reason = "use a bounded channel instead" },
{ path = "futures::channel::mpsc::unbounded", reason = "use a bounded channel instead" },
{ path = "futures_channel::mpsc::unbounded", reason = "use a bounded channel instead" },
]
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all -- -D clippy::all -D warnings
args: --all -- -D clippy::all -D warnings -D clippy::disallowed_method

rustfmt:
name: rustfmt
Expand Down
1 change: 0 additions & 1 deletion fastpay_core/clippy.toml

This file was deleted.

8 changes: 4 additions & 4 deletions fastpay_core/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct Downloader<R, K, V> {
/// Status of previous downloads, indexed by key.
downloads: BTreeMap<K, DownloadStatus<V>>,
/// Command stream of the main handler.
command_receiver: mpsc::UnboundedReceiver<DownloadCommand<K, V>>,
command_receiver: mpsc::Receiver<DownloadCommand<K, V>>,
/// How to send commands to the main handler.
command_sender: mpsc::UnboundedSender<DownloadCommand<K, V>>,
command_sender: mpsc::Sender<DownloadCommand<K, V>>,
}

/// The underlying data-fetching mechanism to be provided by the user.
Expand All @@ -36,7 +36,7 @@ pub trait Requester {

/// Channel for using code to send requests and stop the downloader task.
#[derive(Clone)]
pub struct DownloadHandle<K, V>(mpsc::UnboundedSender<DownloadCommand<K, V>>);
pub struct DownloadHandle<K, V>(mpsc::Sender<DownloadCommand<K, V>>);

/// A command send to the downloader task.
enum DownloadCommand<K, V> {
Expand Down Expand Up @@ -100,7 +100,7 @@ where
where
I: IntoIterator<Item = (K, V)>,
{
let (command_sender, command_receiver) = mpsc::unbounded();
let (command_sender, command_receiver) = mpsc::channel(1024);
let mut downloads = BTreeMap::new();
for (key, value) in known_values {
downloads.insert(key, DownloadStatus::Ready(value));
Expand Down

0 comments on commit 88be98a

Please sign in to comment.