uncleDecart / nkv

Share your state between services using persisted key value storage with notification option
1 stars 0 forks source link

update readme to represent current restructured lib and bins #3

Closed deitch closed 3 months ago

deitch commented 3 months ago

I did look at the second section about threads, but I was lost. It has the following:

Yep, you can use channels to communicate with server

let temp_dir = TempDir::new().expect("Failed to create temporary directory");
let nats_url = env::var("NATS_URL")
            .unwrap_or_else(|_| "nats://localhost:4222".to_string());

let srv = Server::new(nats_url.to_string(), temp_dir.path().to_path_buf()).await.unwrap();

let put_tx = srv.put_tx();
let get_tx = srv.get_tx();
let del_tx = srv.del_tx();

let value: Box<[u8]> = Box::new([1, 2, 3, 4, 5]);
let key = "key1".to_string();
let (resp_tx, mut resp_rx) = mpsc::channel(1);

let _ = put_tx.send(PutMsg{key: key.clone(), value: value.clone(), resp_tx: resp_tx.clone()});

But isn't that talking directly to the server, i.e. not over the protocol via a client?

uncleDecart commented 3 months ago

But isn't that talking directly to the server, i.e. not over the protocol via a client?

Exactly! You can use that not only to talk between processes but between threads (tasks) inside one process, that way you're not using NATS client, just channels inside rust

deitch commented 3 months ago

Oh, so totally different usage. Got it. Updated. Let me know if good to merge.