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

Using async executor of promise should be a problem #1239

Closed
gliluaume opened this issue Jan 8, 2019 · 5 comments

Comments

@gliluaume
Copy link

commented Jan 8, 2019

What version of standard?
12.0.1
What operating system, Node.js, and npm version?

  • Ubuntu 16.04.5 LTS
  • Node.js v10.7.0
  • npm 6.1.0

What did you expect to happen?
Have a warning saying that async function should not be used as a Promise executor in the following code:

'use strict'

const { readFile } = require('fs')

const result = new Promise(async (resolve, reject) => {
  readFile('foo.txt', function (err, result) {
    if (err) {
      reject(err)
    } else {
      resolve(result)
    }
  })
})

result.then(data => console.log(data))

What actually happened?
No problem is shown.

@DiegoRBaquero

This comment has been minimized.

Copy link

commented Jan 21, 2019

I agree, this should be a rule.

Related https://eslint.org/docs/rules/no-async-promise-executor

@stale

This comment has been minimized.

Copy link

commented Apr 21, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Apr 21, 2019

@stale stale bot closed this Apr 28, 2019

@lropero

This comment has been minimized.

Copy link

commented Jul 11, 2019

I don't understand this rule, why can't I have an async executor with the corresponding try/catch blocks surrounding the async operation in order to reject the promise if it fails?

I believe the rule should be something like if-async-promise-executor-then-try-catch-surrounding-await.

Only thing this rule accomplishes is force me to nest .then() constructs which spaghettifies my code.

@feross

This comment has been minimized.

Copy link
Member

commented Jul 11, 2019

@gliluaume @DiegoRBaquero This rule was included in standard 13.

@lropero Please open a new issue to ask a question instead of posting in an already closed issue.

@lropero

This comment has been minimized.

Copy link

commented Jul 13, 2019

Thanks @feross, I opened this request change at ESLint's GitHub discussing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.