Is there any kind of performance problem by returning a callback function in a async function as this code?:
import middy from '@middy/core';
import someFunction from 'someFunction';
async function testFunction (
args,
callback
) {
// code
const data = await someFunction();
return callback(null, {
statusCode: 200,
body: JSON.stringify(data)
});
}
export const handler = middy(testFunction);
I'm using Middy library, I don't think it's relevant to say but just in case.
callbackand returning its return value. Also,asyncis unneeded as you do notawait.callback()) and middlewares (instead of callingnext())." - that means you should use either. Not both. A function returning a promise with the result should never call a callback with that result.callbackandreturnthe result directly.