eslint-plugin-stedi-aws-rules icon indicating copy to clipboard operation
eslint-plugin-stedi-aws-rules copied to clipboard

Prefer async handlers instead of callback based

Open RafalWilinski opened this issue 4 years ago • 1 comments

Rule name

no-callback-handlers

Use case description

Callbacks are considered a bad pattern eventually leading to callback hell. Lambda functions should be written using async/await style for better readability.

Examples

Incorrect

exports.handler =  function(event, context, callback) {
	let calculationResult = await calculate();
	callback(null, calculationResult);
}

Correct

exports.handler = async (event) => {
    let calculationResult = await calculate();
    return calculationResult;
}

RafalWilinski avatar Oct 02 '20 08:10 RafalWilinski

Might be useful to put a rule warning that context.callbackWaitsForEmptyEventLoop doesn't work with async, though

aisamu avatar Oct 02 '20 11:10 aisamu