X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=promise-handling.mjs;h=7f450b3fc53c58f3e93abd821b6490ba7519d260;hb=3d3820c6d32315be92b08f19b905b352dad8506d;hp=ffb42ff96861de27332160a9748cbecf1e8755da;hpb=48f5216deed3bc4d9a64e81822fe8d6bd5c5cdcd;p=benchmarks-js.git diff --git a/promise-handling.mjs b/promise-handling.mjs index ffb42ff..7f450b3 100644 --- a/promise-handling.mjs +++ b/promise-handling.mjs @@ -3,19 +3,12 @@ import Benchmark from 'benny' /** * */ -function promise () { - return new Promise((resolve) => { +async function asyncFunction () { + await new Promise(resolve => { resolve() }) } -/** - * - */ -async function asyncFunction () { - return await promise() -} - Benchmark.suite( 'Promise handling', Benchmark.add('await promise', async () => { @@ -27,10 +20,10 @@ Benchmark.suite( }), Benchmark.add('promise with then().catch()', () => { asyncFunction() - .then((r) => { + .then(r => { return r }) - .catch((e) => { + .catch(e => { console.error(e) }) }), @@ -58,6 +51,6 @@ Benchmark.suite( format: 'table.html', details: true }) -).catch((err) => { +).catch(err => { console.error(err) })