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

v2: Make cancel & cancelAll awaitable #396

Merged
merged 3 commits into from
Jan 20, 2021
Merged

Conversation

maxfierke
Copy link
Collaborator

Cancelation is async, but cancel and cancelAll have not returned promises to enable awaiting cancelation. This PR changes that so the two can be used with async/await and/or Promises to ensure consuming applications can reliably schedule subsequent operations that may depend on cancelation

For example,

@dropTask *myTask() {
  while(1) {
   console.log("hello!");
   yield timeout(1000);
  }
}

@task *restartMyTask() {
  // Note the `yield`. This could also be an `await` or `then` outside of tasks
  yield this.myTask.cancelAll();

  // Without being able to `yield` on `cancelAll` above, the cancelation wouldn't be guaranteed to have taken place before this is called, resulting in `perform` no-oping and dropping the task and myTask would not restart
  this.myTask.perform();
}

Cancelation is async, but cancel and cancelAll have
not returned promises to enable awaiting cancelation
@maxfierke maxfierke changed the title Make cancel & cancelAll awaitable v2: Make cancel & cancelAll awaitable Jan 20, 2021
@maxfierke maxfierke merged commit ba6be13 into v2 Jan 20, 2021
@maxfierke maxfierke deleted the mf-v2_awaitable_cancelation branch February 14, 2021 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant