From 8d9fef3b8955eadfd4820455b422b5bec1cdad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 19 Oct 2023 07:05:00 +0200 Subject: refactor: add WatcherCommunicator helper struct (#20927) This commit introduces "WatcherCommunicator" struct that is used facilitate bi-directional communication between CLI file watcher and the watched function. Prerequisite for https://github.com/denoland/deno/pull/20876 --- cli/graph_util.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cli/graph_util.rs') diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 17437ca99..b90581a14 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -13,6 +13,7 @@ use crate::npm::CliNpmResolver; use crate::resolver::CliGraphResolver; use crate::tools::check; use crate::tools::check::TypeChecker; +use crate::util::file_watcher::WatcherCommunicator; use crate::util::sync::TaskQueue; use crate::util::sync::TaskQueuePermit; @@ -635,14 +636,14 @@ impl<'a> ModuleGraphUpdatePermit<'a> { #[derive(Clone, Debug)] pub struct FileWatcherReporter { - sender: tokio::sync::mpsc::UnboundedSender>, + watcher_communicator: WatcherCommunicator, file_paths: Arc>>, } impl FileWatcherReporter { - pub fn new(sender: tokio::sync::mpsc::UnboundedSender>) -> Self { + pub fn new(watcher_communicator: WatcherCommunicator) -> Self { Self { - sender, + watcher_communicator, file_paths: Default::default(), } } @@ -665,7 +666,10 @@ impl deno_graph::source::Reporter for FileWatcherReporter { } if modules_done == modules_total { - self.sender.send(file_paths.drain(..).collect()).unwrap(); + self + .watcher_communicator + .watch_paths(file_paths.drain(..).collect()) + .unwrap(); } } } -- cgit v1.2.3