node: Add track/untrack support

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder
2022-09-13 10:16:05 +02:00
committed by Alexis Sellier
parent 8fbcb51963
commit d273cd0247
5 changed files with 117 additions and 7 deletions
+26
View File
@@ -54,6 +54,25 @@ pub struct Handle<R: Reactor> {
}
impl<R: Reactor> traits::Handle for Handle<R> {
/// Retrieve or update the project from network.
fn fetch(&self, _id: ProjId) -> Result<(), Error> {
todo!()
}
/// Start tracking the given project. Doesn't do anything if the project is already tracked.
fn track(&self, id: ProjId) -> Result<bool, Error> {
let (sender, receiver) = chan::bounded(1);
self.commands.send(protocol::Command::Track(id, sender))?;
receiver.recv().map_err(Error::from)
}
/// Untrack the given project and delete it from storage.
fn untrack(&self, id: ProjId) -> Result<bool, Error> {
let (sender, receiver) = chan::bounded(1);
self.commands.send(protocol::Command::Untrack(id, sender))?;
receiver.recv().map_err(Error::from)
}
/// Notify the client that a project has been updated.
fn updated(&self, id: ProjId) -> Result<(), Error> {
self.command(protocol::Command::AnnounceRefsUpdate(id))
@@ -80,6 +99,13 @@ pub mod traits {
use super::*;
pub trait Handle {
/// Retrieve or update the project from network.
fn fetch(&self, id: ProjId) -> Result<(), Error>;
/// Start tracking the given project. Doesn't do anything if the project is already
/// tracked.
fn track(&self, id: ProjId) -> Result<bool, Error>;
/// Untrack the given project and delete it from storage.
fn untrack(&self, id: ProjId) -> Result<bool, Error>;
/// Notify the client that a project has been updated.
fn updated(&self, id: ProjId) -> Result<(), Error>;
/// Send a command to the command channel, and wake up the event loop.