Move cancellable to the type system and implement multi-parenting #1

Closed
dgriffen wants to merge 3 commits from dgriffen/rust.eventbus:dev/dgriffen/type-cancel into master
1 changed files with 4 additions and 4 deletions
Showing only changes of commit fedb32d242 - Show all commits

View File

@ -72,7 +72,6 @@ macro_rules! post_event {
fun(event); fun(event);
} }
},)+); // big tuple of (Handlers<type>, Handlers<type>, Handlers<type>, Handlers<type>, ...) },)+); // big tuple of (Handlers<type>, Handlers<type>, Handlers<type>, Handlers<type>, ...)
} }
} }
} }
@ -97,7 +96,7 @@ macro_rules! post_event_cancellable {
} }
test(event); test(event);
let cancelled = ($({ let cancelled = [$({
// event type setup // event type setup
static EVENT_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT; static EVENT_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
static EVENT_ID_INIT: ::std::sync::Once = ::std::sync::ONCE_INIT; static EVENT_ID_INIT: ::std::sync::Once = ::std::sync::ONCE_INIT;
@ -110,15 +109,16 @@ macro_rules! post_event_cancellable {
let handlers = $crate::get_post_targets::<$t>(bus, event, id); let handlers = $crate::get_post_targets::<$t>(bus, event, id);
for (_pri, fun) in handlers.iter() { for (_pri, fun) in handlers.iter() {
fun(event as &mut $t);
if Cancellable::cancelled(event) { if Cancellable::cancelled(event) {
break; break;
} }
fun(event as &mut $t);
} }
event.cancelled() event.cancelled()
},)+); // big tuple of (Handlers<type>, Handlers<type>, Handlers<type>, Handlers<type>, ...) },)+]; // big tuple of (Handlers<type>, Handlers<type>, Handlers<type>, Handlers<type>, ...)
cancelled.iter().fold(false, |n, i| n || *i)
} }
} }
} }