Skip to content

fix(task): remove cancel method from Task trait(#884)#899

Merged
jstarry merged 1 commit into
yewstack:masterfrom
kakoc:fix/884
Jan 28, 2020
Merged

fix(task): remove cancel method from Task trait(#884)#899
jstarry merged 1 commit into
yewstack:masterfrom
kakoc:fix/884

Conversation

@kakoc
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread src/services/fetch.rs Outdated
let handle = self
.0
.take()
.expect("tried to cancel request fetching twice");
Copy link
Copy Markdown
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

Comment thread src/services/interval.rs Outdated
fn drop(&mut self) {
if self.is_active() {
self.cancel();
let handle = self.0.take().expect("tried to cancel interval twice");
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

kakoc commented Jan 26, 2020

@jstarry changed.

Comment thread examples/dashboard/src/lib.rs Outdated
}
WsAction::Disconnect => {
self.ws.take().unwrap().cancel();
drop(self.ws.take().unwrap());
Copy link
Copy Markdown
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

Comment thread examples/timer/src/lib.rs Outdated
@@ -77,7 +77,7 @@ impl Component for Model {
}
Msg::Cancel => {
if let Some(mut task) = self.job.take() {
Copy link
Copy Markdown
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
Copy Markdown
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