-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(task): remove cancel
method from Task
trait(#884)
#899
Conversation
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.
just a few nits, the expect messages aren't accurate anymore. Otherwise this looks good, thanks!
src/services/fetch.rs
Outdated
let handle = self | ||
.0 | ||
.take() | ||
.expect("tried to cancel request fetching twice"); |
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.
nit: this is no longer accurate, unwrap
should be fine because this is impossible now
src/services/interval.rs
Outdated
} | ||
|
||
impl Drop for IntervalTask { | ||
fn drop(&mut self) { | ||
if self.is_active() { | ||
self.cancel(); | ||
let handle = self.0.take().expect("tried to cancel interval twice"); |
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.
nit: same here, unwrap
should be fine
096192e
to
26491d4
Compare
@jstarry changed. |
examples/dashboard/src/lib.rs
Outdated
@@ -167,7 +167,7 @@ impl Component for Model { | |||
} | |||
} | |||
WsAction::Disconnect => { | |||
self.ws.take().unwrap().cancel(); | |||
drop(self.ws.take().unwrap()); |
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.
Drop will be called once the task goes out of scope so self.ws.take()
should be enough
examples/timer/src/lib.rs
Outdated
@@ -77,7 +77,7 @@ impl Component for Model { | |||
} | |||
Msg::Cancel => { | |||
if let Some(mut task) = self.job.take() { |
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.
Same here just call take()
In order to avoid misuse It was decided to remove `cancel` from `Task` trait and delegate such logic to `Drop`.
@jstarry changed. Thanks for the review. |
Fixes #884.
In order to avoid misuse It was decided to remove
cancel
fromTask
traitand delegate such logic to
Drop
.