Skip to content
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

Merged
merged 1 commit into from
Jan 28, 2020

Conversation

kakoc
Copy link
Contributor

@kakoc kakoc commented Jan 26, 2020

Fixes #884.

In order to avoid misuse It was decided to remove cancel from Task trait
and delegate such logic to Drop.

@kakoc kakoc requested a review from jstarry January 26, 2020 15:29
Copy link
Member

@jstarry jstarry left a 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!

let handle = self
.0
.take()
.expect("tried to cancel request fetching twice");
Copy link
Member

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

}

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");
Copy link
Member

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

@kakoc kakoc force-pushed the fix/884 branch 2 times, most recently from 096192e to 26491d4 Compare January 26, 2020 16:38
@kakoc
Copy link
Contributor Author

kakoc commented Jan 26, 2020

@jstarry changed.

@@ -167,7 +167,7 @@ impl Component for Model {
}
}
WsAction::Disconnect => {
self.ws.take().unwrap().cancel();
drop(self.ws.take().unwrap());
Copy link
Member

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

@@ -77,7 +77,7 @@ impl Component for Model {
}
Msg::Cancel => {
if let Some(mut task) = self.job.take() {
Copy link
Member

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`.
@kakoc
Copy link
Contributor Author

kakoc commented Jan 27, 2020

@jstarry changed. Thanks for the review.

@jstarry jstarry merged commit 5629f37 into yewstack:master Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Too easy to cancel inactive Tasks
2 participants