Skip to content

Bugfix/run twice #10

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

Merged
merged 4 commits into from
Jul 5, 2023
Merged

Bugfix/run twice #10

merged 4 commits into from
Jul 5, 2023

Conversation

murilopolese
Copy link
Contributor

Problem:

If you press the button run twice a few breaking situation happen:

  • Interrupt first execution but won't run the second time
  • Sometimes get stuck on raw repl
  • Sometimes run button stops working

This will also make other functions to break (save, list files, etc...)
When entering raw repl again it executes some code automatically a couple of times.
When entering raw repl, typing 'print(123)' and hitting control+D will execute and leave raw repl. It should not leave raw repl.

Solution:

Board was getting stuck because promises weren't being "canceled".
Following cue from micropython-ctl implementation: The function to reject the run promise is stored locally on board class and called before attempting other operations (stop and reset).

Future improvement:

Renaming methods because right now it's confusing what's keyboard interrupt and what is stopping a program or getting a prompt. Confusing.

Copy link

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

I did not try it in action but read through the code changes.

return new Promise(async (resolve, reject) => {
if (this.reject_run) {
this.reject_run('re run')
this.reject_run = null

Choose a reason for hiding this comment

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

This line is not necessary here, but if you want to keep setting the rejected promise to null, maybe you can have a method for all three occurrences.

function ensureRejected(message) {
  if (this.reject_run) {
    this.reject_run(new Error(message));
    this.reject_run = null;
  }
}

Any reason you prefer rejecting with a string instead of an Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it should definitely be an error. I just don't find the helper function really helpful here. I'm also not sure if this is going to be the final solution ™️ so I'd prefer keeping things a bit more unrolled.

await this.exit_raw_repl()
return resolve(output)
} catch (e) {
reject(e)

Choose a reason for hiding this comment

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

Question: if there is an error here, and the promise is rejected, then the next run call will find this._reject_run to be not null and will reject it, but nothing will happen, as it has already been rejected. Is this expected behavior, or would it be better to set this.reject_run to null in the catch?

Copy link

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

@murilopolese murilopolese merged commit 4648998 into main Jul 5, 2023
@murilopolese murilopolese deleted the bugfix/run-twice branch July 5, 2023 12:51
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.

3 participants