let pusher = factory.pusher_open()?.listen(&url)?;
let puller = factory.puller_open()?.dial(&url)?;
thread::spawn(move || -> NngReturn {
let mut push_ctx = pusher.create_async_context()?;
loop {
let msg = msg::NngMsg::new()?;
push_ctx.send(msg).wait().unwrap()?;
}
Ok(())
});
thread::spawn(move || -> NngReturn {
let mut pull_ctx = puller.create_async_context()?;
loop {
pull_ctx.receive().take(1).wait();
}
Ok(())
});
Will crash with:
pushpull_tests-7035aebbdce1069e(57332,0x700001ce8000) malloc: *** error for object 0xf: pointer being freed was not allocated
pushpull_tests-7035aebbdce1069e(57332,0x700001ce8000) malloc: *** set a breakpoint in malloc_error_break to debug
The problem is the rapid creation of the receive future:
loop {
pull_ctx.receive() // this
}
Can be avoided by only creating the future once:
// No `loop{}`
pull_ctx.receive()
.for_each(|_|{
// Do stuff
Ok(())
}).wait().unwrap();
Code like:
Will crash with:
The problem is the rapid creation of the receive future:
Can be avoided by only creating the future once: