caolan / async

Async utilities for node and the browser
http://caolan.github.io/async/
MIT License
28.15k stars 2.41k forks source link

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

Open bbuck opened 3 months ago

bbuck commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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