Skip to content

Commit

Permalink
Added a namespace thing, its not done
Browse files Browse the repository at this point in the history
  • Loading branch information
d1ngd0 committed Apr 7, 2024
1 parent bb39c78 commit d6b55ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod router;
34 changes: 19 additions & 15 deletions src/route.rs → src/router.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{
collections::HashMap,
sync::{
mpsc::{self, Receiver, SyncSender},
RwLock,
},
};
use std::collections::HashMap;

use crate::Dapt;
use dapt::Dapt;
use tokio::sync::{
mpsc::{channel, Receiver, Sender},
RwLock,
};

// Router is a collection of namespaces which allows for registering
// channels to read and write to namespace. Namespaces are created
Expand All @@ -25,7 +23,7 @@ pub struct Router {
// can be set on the registers themselves.
pub struct Namespace {
inputs: RwLock<HashMap<String, Receiver<Dapt>>>,
outputs: RwLock<HashMap<String, SyncSender<Dapt>>>,
outputs: RwLock<HashMap<String, Sender<Dapt>>>,
}

impl Namespace {
Expand All @@ -36,19 +34,25 @@ impl Namespace {
}
}

pub fn input(&mut self, name: String, buffer: usize) -> SyncSender<Dapt> {
let (send, recv) = mpsc::sync_channel(buffer);
self.inputs.write().unwrap().insert(name, recv);
pub async fn input(&mut self, name: String, buffer: usize) -> Sender<Dapt> {
let (send, recv) = channel(buffer);
self.inputs.write().await.insert(name, recv);
send
}

pub fn output(&mut self, name: String, buffer: usize) -> Receiver<Dapt> {
let (send, recv) = mpsc::sync_channel(buffer);
self.outputs.write().unwrap().insert(name, send);
pub async fn output(&mut self, name: String, buffer: usize) -> Receiver<Dapt> {
let (send, recv) = channel(buffer);
self.outputs.write().await.insert(name, send);
recv
}
}

impl Drop for Namespace {
fn drop(&mut self) {
// Clean up the namespace
}
}

impl Default for Namespace {
fn default() -> Self {
Namespace::new()
Expand Down

0 comments on commit d6b55ab

Please sign in to comment.