Skip to content

Processing values from signals (match_signal closure) #393

Discussion options

You must be logged in to vote

After all I found a solution to get the data out of the closure using Arc and Mutex:

// Note: Untested modification of the example
let result: Arc<Mutex<Vec<ComExampleDbustestHelloHappened>>> = Arc::new(Mutex::new(Vec::new()));
let result_2 = result.clone();
let _id = proxy.match_signal(|h: ComExampleDbustestHelloHappened, _: &Connection, _: &Message| {
    println!("Hello happened from sender: {}", h.sender);
    result_2.lock().unwrap().push(h);
    true
});
println!("{:?}", result);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@diwic
Comment options

Answer selected by debug-richard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants