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

Returning promise from non-async function doesn't work #1733

Closed
sergejostir opened this issue Oct 31, 2020 · 2 comments
Closed

Returning promise from non-async function doesn't work #1733

sergejostir opened this issue Oct 31, 2020 · 2 comments

Comments

@sergejostir
Copy link

What version of async are you using?
3.2.0

Which environment did the issue occur in (Node/browser/Babel/Typescript version)
Node

What did you do? Please include a minimal reproducible case illustrating issue.

async.waterfall([
  () => Promise.resolve(),
  async () => {
    console.log('not called');
  },
]);

What did you expect to happen?
I would expect this snippet to work properly. Async function is just a normal function that 100% returns Promise. If I return promise from the non-async function the result is exactly the same, so I do not understand why async package fails in this case.

What was the actual result?
The code did not execute properly.

@aearly
Copy link
Collaborator

aearly commented Oct 31, 2020

Async function is just a normal function that 100% returns Promise.

This is not entirely true, async functions have a detectable AsyncFunction type we can handle separately. If you're going to return a promise, it must explicitly use the async keyword so the library can handle it properly (and also not pass a callback).

@sergejostir
Copy link
Author

I see. It confused me because I expected to get the same result for using native async function and simply returning a promise. I found an explanation here now: #1386

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

No branches or pull requests

2 participants