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

Mixing native async and Node callback functions seems to cause unexpected behavior #1964

Open
bbuck opened this issue May 7, 2024 · 2 comments

Comments

@bbuck
Copy link

bbuck commented May 7, 2024

It seems async functions that return nothing (implicitly resolves to undefined) pass on undefined as a value to the next function in line which I would not expect to happen. Returning undefined from a function is the default behavior of "returning nothing."

What version of async are you using?

3.2.4

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

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

async.waterfall(
  [
    async () => {}, 
    (...args) => { 
      args.at(-1)(null, args); 
    },
  ],
  (error, result) => {
    console.log('error', error, '// result', result);
  },
);

// > error null // result [ undefined, [Function (anonymous)] ]

What did you expect to happen?

The result array to have a single element, the callback function.

What was the actual result?

The array contains two items, the undefined resolved from the native async function and the callback function passed to the Node-style async function.

@bbuck
Copy link
Author

bbuck commented May 7, 2024

Seems to affect 3.2.5 as well, just wanted to verify: https://runkit.com/bbuck/native-async-functions-in-async-waterfall-pass-undefined

@code-lixm
Copy link

I also encountered this problem. Using native Async will lose Callback and can only use Promise

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