mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-06-28 20:19:26 +00:00
The client, not the app, now drives the transport; events are delivered asynchronously, per ADR 0001. - ChatClient owns Arc<Mutex<Core>> + a worker thread. - The worker select!s over the inbound and shutdown channels; Drop joins it. Outbound runs on the caller's thread. - A single Transport (DeliveryService + inbound()) owns both directions of the boundary, so the client takes one transport rather than a (delivery, inbound) pair. InProcessDelivery::new, CDelivery, and chat-cli's transports implement it. - FFI replaces client_receive with client_push_inbound + client_poll_events. - chat-cli drains Receiver<Event>; inbound and event channels are both crossbeam. - Corrects ADR 0001's inbound sequence to push — the worker parks on select!, it never polls.
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
use logos_chat::{ChatClient, Event, InProcessDelivery, MessageBus};
|
|
use std::time::Duration;
|
|
|
|
fn main() {
|
|
let bus = MessageBus::default();
|
|
let saro_delivery = InProcessDelivery::new(bus.clone());
|
|
let raya_delivery = InProcessDelivery::new(bus);
|
|
|
|
let (mut saro, saro_events) = ChatClient::new("saro", saro_delivery);
|
|
let (mut raya, raya_events) = ChatClient::new("raya", raya_delivery);
|
|
|
|
let raya_bundle = raya.create_intro_bundle().unwrap();
|
|
saro.create_conversation(&raya_bundle, b"hello raya")
|
|
.unwrap();
|
|
|
|
// Raya's worker delivers the new conversation, then its initial message.
|
|
let raya_convo_id = match raya_events.recv_timeout(Duration::from_secs(5)).unwrap() {
|
|
Event::ConversationStarted { convo_id, .. } => convo_id,
|
|
other => panic!("expected ConversationStarted, got {other:?}"),
|
|
};
|
|
if let Event::MessageReceived { content, .. } =
|
|
raya_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
|
{
|
|
println!(
|
|
"Raya received: {:?}",
|
|
std::str::from_utf8(&content).unwrap()
|
|
);
|
|
}
|
|
|
|
raya.send_message(&raya_convo_id, b"hi saro").unwrap();
|
|
|
|
if let Event::MessageReceived { content, .. } =
|
|
saro_events.recv_timeout(Duration::from_secs(5)).unwrap()
|
|
{
|
|
println!(
|
|
"Saro received: {:?}",
|
|
std::str::from_utf8(&content).unwrap()
|
|
);
|
|
}
|
|
|
|
println!("Message exchange complete.");
|
|
}
|