mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-08 00:43:10 +00:00
some logic to panic if a proper event callback hasn't been set
This commit is contained in:
parent
14aca7f403
commit
dad471a114
@ -85,7 +85,7 @@ impl TicTacToeApp {
|
|||||||
// Establish a closure that handles the incoming messages
|
// Establish a closure that handles the incoming messages
|
||||||
self.waku.ctx.waku_set_event_callback(my_closure).expect("set event call back working");
|
self.waku.ctx.waku_set_event_callback(my_closure).expect("set event call back working");
|
||||||
|
|
||||||
// Subscribe to desired topic
|
// Subscribe to desired topic using the relay protocol
|
||||||
// self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe");
|
// self.waku.relay_subscribe(&self.game_topic.to_string()).expect("waku should subscribe");
|
||||||
|
|
||||||
let content_topic = WakuContentTopic::new("waku", "2", "tictactoegame", Encoding::Proto);
|
let content_topic = WakuContentTopic::new("waku", "2", "tictactoegame", Encoding::Proto);
|
||||||
|
|||||||
@ -10,12 +10,21 @@ pub struct WakuNodeContext {
|
|||||||
|
|
||||||
impl WakuNodeContext {
|
impl WakuNodeContext {
|
||||||
pub fn new(obj_ptr: *mut c_void) -> Self {
|
pub fn new(obj_ptr: *mut c_void) -> Self {
|
||||||
Self {
|
let me = Self {
|
||||||
obj_ptr: obj_ptr,
|
obj_ptr: obj_ptr,
|
||||||
msg_observer: Arc::new(Mutex::new(Box::new(|_response| {
|
msg_observer: Arc::new(Mutex::new(Box::new(|_| {}))),
|
||||||
println!("msg observer not set")
|
};
|
||||||
}))),
|
|
||||||
}
|
// By default we set a callback that will panic if the user didn't specify a valid callback.
|
||||||
|
// And by valid callback we mean a callback that can properly handle the waku events.
|
||||||
|
me.waku_set_event_callback(WakuNodeContext::panic_callback)
|
||||||
|
.expect("correctly set default callback");
|
||||||
|
me
|
||||||
|
}
|
||||||
|
|
||||||
|
// default callback that does nothing. A valid callback should be set
|
||||||
|
fn panic_callback(_response: LibwakuResponse) {
|
||||||
|
panic!("callback not set. Please use waku_set_event_callback to set a valid callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ptr(&self) -> *mut c_void {
|
pub fn get_ptr(&self) -> *mut c_void {
|
||||||
|
|||||||
@ -32,7 +32,7 @@ async fn test_echo_messages(
|
|||||||
content_topic: WakuContentTopic,
|
content_topic: WakuContentTopic,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
// setting a naïve event handler to avoid appearing ERR messages in logs
|
// setting a naïve event handler to avoid appearing ERR messages in logs
|
||||||
node1.ctx.waku_set_event_callback(&|_| {});
|
let _ = node1.ctx.waku_set_event_callback(&|_| {});
|
||||||
|
|
||||||
let rx_waku_message: Arc<Mutex<WakuMessage>> = Arc::new(Mutex::new(WakuMessage::default()));
|
let rx_waku_message: Arc<Mutex<WakuMessage>> = Arc::new(Mutex::new(WakuMessage::default()));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user