X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=promise-handling.js;h=11e0a96493056430a470792173f8fd4fd50f04d9;hb=77d3850e9eb4f27dfa31bebc8e02f400848517ad;hp=002be6d429392264772e61aff6f617bebee0c277;hpb=7e8612886ac3d42901e452b0bd36781410f37b58;p=benchmarks-js.git diff --git a/promise-handling.js b/promise-handling.js index 002be6d..11e0a96 100644 --- a/promise-handling.js +++ b/promise-handling.js @@ -13,15 +13,32 @@ function promise () { * */ async function asyncFunction () { - await promise() + return await promise() } Benchmark.suite( 'Promise handling', Benchmark.add('await promise', async () => { - await asyncFunction() + try { + return await asyncFunction() + } catch (e) { + console.error(e) + } }), - Benchmark.add('promise', () => { + Benchmark.add('promise with then().catch()', () => { + asyncFunction() + .then(r => { + return r + }) + .catch(e => { + console.error(e) + }) + }), + Benchmark.add('voided promise', () => { + // eslint-disable-next-line no-void + void asyncFunction() + }), + Benchmark.add('mishandled promise', () => { asyncFunction() }), Benchmark.cycle(), @@ -41,4 +58,6 @@ Benchmark.suite( format: 'table.html', details: true }) -) +).catch(err => { + console.error(err) +})