New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add monitor loop to supervisor logic #9
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9 +/- ##
==========================================
- Coverage 64.69% 64.50% -0.20%
==========================================
Files 6 7 +1
Lines 966 1034 +68
Branches 184 195 +11
==========================================
+ Hits 625 667 +42
- Misses 109 120 +11
- Partials 232 247 +15
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick review of some more superficial stuff, I'm going to take another look later this weekend when I'm feeling less distracted.
Co-authored-by: Zephyr Shannon <geoffpshannon@gmail.com>
Co-authored-by: Zephyr Shannon <geoffpshannon@gmail.com>
@@ -0,0 +1,23 @@ | |||
use futures::future::{abortable, AbortHandle, Aborted, BoxFuture, Future, FutureExt}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this file by accident, currently is not being included in the lib.rs
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now, other than that one new Sync
bound which looks a bit fishy
@@ -41,7 +41,7 @@ pub struct EventNotifier(Arc<NotifyFn>); | |||
impl EventNotifier { | |||
pub fn new<F, O>(notify0: F) -> Self | |||
where | |||
F: Fn(Event) -> O + 'static, | |||
F: (Fn(Event) -> O) + Send + Sync + 'static, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this Sync
bound is again not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change
diff --git a/src/events.rs b/src/events.rs
index 74f1b49..a5a65a0 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -31,7 +31,7 @@ pub struct NodeData {
/// NotifyFn is used by the supervision API to send events to an interested
/// listener.
-type NotifyFn = Box<dyn (Fn(Event) -> BoxFuture<'static, ()>) + Send + Sync>;
+type NotifyFn = Box<dyn (Fn(Event) -> BoxFuture<'static, ()>) + Send>;
/// EventNotifier is used by the internal supervision API to send events about a
/// running supervision tree
@@ -41,7 +41,7 @@ pub struct EventNotifier(Arc<NotifyFn>);
impl EventNotifier {
pub fn new<F, O>(notify0: F) -> Self
where
- F: (Fn(Event) -> O) + Send + Sync + 'static,
+ F: (Fn(Event) -> O) + Send + 'static,
O: Future<Output = ()> + FutureExt + Send + 'static,
{
let notify = move |ev| {
causes this compilation error:
❯ cargo test
Compiling capataz v0.0.0 (/home/roman/tmp/rust-capataz)
error[E0277]: `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
--> src/supervisor/mod.rs:480:30
|
480 | let start_notifier = StartNotifier::from_oneshot(started_send);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
|
::: src/notifier.rs:8:5
|
8 | / pub fn from_oneshot(sender: oneshot::Sender<Result<T, E>>) -> Self
9 | | where
10 | | T: Send + 'static,
11 | | E: Send + 'static,
... |
15 | | }))
16 | | }
| |_____- required by `notifier::StartNotifier::<T, E>::from_oneshot`
|
= help: the trait `std::marker::Sync` is not implemented for `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)`
= note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>`
= note: required because it appears within the type `std::boxed::Box<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::boxed::Box<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>>`
= note: required because it appears within the type `events::EventNotifier`
= note: required because it appears within the type `supervisor::SpecMeta`
= note: required because it appears within the type `supervisor::Spec`
= note: required because it appears within the type `(supervisor::Spec, std::sync::Arc<supervisor::StartError>)`
error[E0277]: `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
--> src/supervisor/mod.rs:488:27
|
488 | let join_handle = task::spawn(run_supervisor_monitor(
| ^^^^^^^^^^^ `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)` cannot be shared between threads safely
|
::: /home/roman/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.22/src/task/spawn.rs:128:20
|
128 | T::Output: Send + 'static,
| ---- required by this bound in `tokio::spawn`
|
= help: the trait `std::marker::Sync` is not implemented for `(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)`
= note: required because of the requirements on the impl of `std::marker::Sync` for `std::ptr::Unique<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>`
= note: required because it appears within the type `std::boxed::Box<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>`
= note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::boxed::Box<(dyn std::ops::Fn(events::Event) -> std::pin::Pin<std::boxed::Box<(dyn futures::Future<Output = ()> + std::marker::Send + 'static)>> + std::marker::Send + 'static)>>`
= note: required because it appears within the type `events::EventNotifier`
= note: required because it appears within the type `supervisor::SpecMeta`
= note: required because it appears within the type `supervisor::Spec`
= note: required because it appears within the type `supervisor::SupervisorResult`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
error: could not compile `capataz`.
Context
This pull request modifies the supervisor logic in a way that:
start
is calledrun
method)