Make channel buffers configurable
This commit is contained in:
parent
5d11ccaa71
commit
249c581dc9
|
@ -2069,6 +2069,7 @@ version = "1.17.1"
|
|||
dependencies = [
|
||||
"color-eyre",
|
||||
"command-group",
|
||||
"derive_builder",
|
||||
"dunce",
|
||||
"futures",
|
||||
"miette",
|
||||
|
|
|
@ -21,6 +21,7 @@ thiserror = "1.0.26"
|
|||
tracing = "0.1.26"
|
||||
dunce = "1.0.2"
|
||||
futures = "0.3.16"
|
||||
derive_builder = "0.10.2"
|
||||
|
||||
[dependencies.command-group]
|
||||
version = "1.0.5"
|
||||
|
|
|
@ -1,3 +1,37 @@
|
|||
use derive_builder::Builder;
|
||||
|
||||
/// Configuration for [`Watchexec`][crate::Watchexec].
|
||||
///
|
||||
/// This is used both for constructing the instance and to reconfigure it at runtime, though note
|
||||
/// that some fields are only applied at construction time.
|
||||
///
|
||||
/// You should prefer the [`ConfigBuilder`] rather than using this directly. This struct is marked
|
||||
/// non-exhaustive such that new options may be added without breaking change.
|
||||
#[derive(Builder, Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
#[builder(build_fn(name = "finish"))]
|
||||
pub struct Config {
|
||||
/// Working data for the filesystem event source.
|
||||
///
|
||||
/// This notably includes the path set to be watched.
|
||||
#[builder(default)]
|
||||
pub fs: crate::fs::WorkingData,
|
||||
|
||||
/// Internal: the buffer size of the channel which carries runtime errors.
|
||||
///
|
||||
/// The default (64) is usually fine. If you expect a much larger throughput of runtime errors,
|
||||
/// adjusting this value may help. (Fixing whatever is causing the errors may also help.)
|
||||
///
|
||||
/// Only used at construction time, cannot be changed via reconfiguration.
|
||||
#[builder(default = "64")]
|
||||
pub error_channel_size: usize,
|
||||
|
||||
/// Internal: the buffer size of the channel which carries events.
|
||||
///
|
||||
/// The default (1024) is usually fine. If you expect a much larger throughput of events,
|
||||
/// adjusting this value may help.
|
||||
///
|
||||
/// Only used at construction time, cannot be changed via reconfiguration.
|
||||
#[builder(default = "1024")]
|
||||
pub event_channel_size: usize,
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
#![forbid(unsafe_code)]
|
||||
|
||||
// the toolkit to make your own
|
||||
pub mod command;
|
||||
pub mod error;
|
||||
pub mod event;
|
||||
pub mod fs;
|
||||
pub mod command;
|
||||
pub mod signal;
|
||||
|
||||
// the core experience
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{mem::take, sync::Arc};
|
||||
|
||||
use futures::FutureExt;
|
||||
use tokio::{
|
||||
|
@ -22,16 +22,16 @@ pub struct Watchexec {
|
|||
}
|
||||
|
||||
impl Watchexec {
|
||||
pub fn new(config: Config) -> Result<Self, CriticalError> {
|
||||
let (fs_s, fs_r) = watch::channel(config.fs);
|
||||
pub fn new(mut config: Config) -> Result<Self, CriticalError> {
|
||||
let (fs_s, fs_r) = watch::channel(take(&mut config.fs));
|
||||
|
||||
let notify = Arc::new(Notify::new());
|
||||
let start_lock = notify.clone();
|
||||
let handle = spawn(async move {
|
||||
notify.notified().await;
|
||||
|
||||
let (er_s, er_r) = mpsc::channel(64); // TODO: configure?
|
||||
let (ev_s, ev_r) = mpsc::channel(1024); // TODO: configure?
|
||||
let (er_s, er_r) = mpsc::channel(config.error_channel_size);
|
||||
let (ev_s, ev_r) = mpsc::channel(config.event_channel_size);
|
||||
|
||||
macro_rules! subtask {
|
||||
($task:expr) => {
|
||||
|
|
Loading…
Reference in New Issue