From b16282da6e560b83d8906e9660bf74774c3a3362 Mon Sep 17 00:00:00 2001 From: Matthew Forrester Date: Mon, 26 Dec 2022 15:38:46 +0000 Subject: [PATCH] fix: restarting already running. feat: publish restartable to JS API --- Cargo.lock | 2 +- examples/data-table/index.html | 528 +++++++++++++++++++++++++++++++++ src/main.rs | 39 ++- 3 files changed, 559 insertions(+), 10 deletions(-) create mode 100644 examples/data-table/index.html diff --git a/Cargo.lock b/Cargo.lock index 4099cc2..b56c4a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -496,7 +496,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "wv_linewise" -version = "0.2.0" +version = "0.3.0" dependencies = [ "clap", "serde", diff --git a/examples/data-table/index.html b/examples/data-table/index.html new file mode 100644 index 0000000..edcb5a9 --- /dev/null +++ b/examples/data-table/index.html @@ -0,0 +1,528 @@ + + + + + + +
+ + + + + +
+
+
+ +
+ + + + + diff --git a/src/main.rs b/src/main.rs index 4de6e32..2e86c49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,7 @@ struct MessageError { error: String } #[derive(Debug, Serialize)] -struct StreamDetailsDetails { rewindable: bool } +struct StreamDetailsDetails { rewindable: bool, restartable: bool } #[derive(Debug)] @@ -254,6 +254,18 @@ enum CommChannel { Pending(PendingCommChannel), } + +impl CommChannel { + fn get_filename(&self) -> Option<&str> { + match self { + CommChannel::Finished => None, + CommChannel::Started(StartedCommChannel { original_filename, ..}) => Some(original_filename), + CommChannel::Pending(PendingCommChannel { filename, ..}) => Some(filename), + } + } +} + + type Channels = HashMap; #[derive(Debug)] @@ -355,6 +367,14 @@ fn get_reader(name: &str) -> std::io::Result> { } +fn stream_restartable(opts_restartable: bool, original_filename: &str) -> bool { + match (opts_restartable, original_filename) { + (true, "-") => false, + (true, _) => true, + (_, _) => false, + } +} + fn stream(filename: String, pause_at: u64) -> StartedCommChannel { @@ -562,7 +582,7 @@ fn start_comm_channel(msg: &StartingMessage, channels: &mut Channels) -> bool { ); true }, - CommChannel::Started(_scc) => false, + CommChannel::Started(scc) => true, CommChannel::Finished => false, } }).unwrap_or(false) @@ -703,7 +723,11 @@ fn get_stream_to_manage(msg_str: &str, opts: &Opts, mut channels: &mut Channels) response: Option::Some(Response::StreamDetails(StreamDetails { name: request.name.to_string(), details: StreamDetailsDetails { - rewindable: false + rewindable: false, + restartable: stream_restartable( + opts.restartable, + channels.get(&request.name).map(|c| c.get_filename()).flatten().unwrap_or("") + ) } })), request: Option::Some(msg), @@ -890,16 +914,13 @@ fn main() { Some(CommChannel::Started(c)) => { let original_filename = c.original_filename.to_owned(); let manage_stream_resp = manage_stream(&mut send, c, &name); - match (manage_stream_resp.finished, opts.restartable, original_filename.as_ref()) { - (true, _, "-") => { + match (manage_stream_resp.finished, stream_restartable(opts.restartable, original_filename.as_ref())) { + (true, false) => { channels.insert(name.to_owned(), CommChannel::Finished ); } - (true, true, _) => { + (true, true) => { channels.insert(name.to_owned(), CommChannel::Pending(PendingCommChannel { filename: original_filename }) ); } - (true, false, _) => { - channels.insert(name.to_owned(), CommChannel::Finished ); - } _ => {}, } if let Some(to_send) = manage_stream_resp.pending_response {