build: bump volta node version
[benchmarks-js.git] / promise-handling.mjs
CommitLineData
4676a95c 1import { bench, group, run } from 'tatami-ng'
ed2968f2 2
e9bfc28e
JB
3/**
4 *
5 */
bcd364e0
JB
6async function asyncFunction () {
7 await new Promise(resolve => {
7e861288
JB
8 resolve()
9 })
ed2968f2
JB
10}
11
ab9a08f3
JB
12group('Promise handling', () => {
13 bench('await promise', async () => {
57f62217
JB
14 try {
15 return await asyncFunction()
16 } catch (e) {
17 console.error(e)
18 }
ab9a08f3
JB
19 })
20 bench('promise with then().catch()', () => {
57f62217 21 asyncFunction()
f913c68c 22 .then(r => {
57f62217
JB
23 return r
24 })
4aa2893a 25 .catch(console.error)
ab9a08f3
JB
26 })
27 bench('voided promise', () => {
1f89b386
JB
28 // eslint-disable-next-line no-void
29 void asyncFunction()
ab9a08f3
JB
30 })
31 bench('mishandled promise', () => {
ed2968f2
JB
32 asyncFunction()
33 })
ab9a08f3
JB
34})
35
36await run({
37 units: true
38})