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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rejecting promises with erros instead of strings
  • Loading branch information
murilopolese committed Jul 5, 2023
commit 17661ab983937282974e98c64be0cc7ebec4e8c4
6 changes: 3 additions & 3 deletions micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class MicroPythonBoard {
data_consumer = data_consumer || function() {}
return new Promise(async (resolve, reject) => {
if (this.reject_run) {
this.reject_run('re run')
this.reject_run(new Error('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.

}
this.reject_run = reject
Expand All @@ -176,7 +176,7 @@ class MicroPythonBoard {

async stop() {
if (this.reject_run) {
this.reject_run('pre stop')
this.reject_run(new Error('pre stop'))
this.reject_run = null
}
// Dismiss any data with ctrl-C
Expand All @@ -186,7 +186,7 @@ class MicroPythonBoard {

async reset() {
if (this.reject_run) {
this.reject_run('pre reset')
this.reject_run(new Error('pre reset'))
this.reject_run = null
}
// Dismiss any data with ctrl-C
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy