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

Added a way to stop the operation #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

taras
Copy link
Member

@taras taras commented Jan 15, 2024

Motivation

I want to be able to stop the loader when encountering an error. This is useful when encountering a "VPN not connected" situation. In this case, I want to stop the operation and not have it do anything else.

Approach

  1. Added a new state type called "stopped"
  2. Added check for "stopped" in the update function that runs suspend
  3. Refactored to use channels to allow interrupting the loading driver when encountering a stopped state

TODOs and Open Questions

  • Add the ability to resume when the connection is restored

@taras taras requested a review from cowboyd January 15, 2024 23:43
Base automatically changed from tm/separate-retry-from-initial-attempt to main January 16, 2024 14:50
for (const value of yield* each(channel)) {
setState(value);
if (value.type === "stopped") {
throw new Error("Forced interrupt")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just stop your iteration and the updates task will win your race. I'd do that since it is an expected condition.

Suggested change
throw new Error("Forced interrupt")
break;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm throwing the error to short-circuit the other child operations. Will break do the same here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read it correctly, then yes. breaking here exits the loop, which then causes the updates task to win the race, which then causes the main task invoked with run() to return, which then shuts down everything created in that scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, I didn't catch that.

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.

2 participants