Commit | Line | Data |
---|---|---|
4676a95c | 1 | import { bench, group, run } from 'tatami-ng' |
ed2968f2 | 2 | |
e9bfc28e JB |
3 | /** |
4 | * | |
5 | */ | |
bcd364e0 JB |
6 | async function asyncFunction () { |
7 | await new Promise(resolve => { | |
7e861288 JB |
8 | resolve() |
9 | }) | |
ed2968f2 JB |
10 | } |
11 | ||
ab9a08f3 JB |
12 | group('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 | ||
36 | await run({ | |
ebf80fe4 | 37 | units: true, |
ab9a08f3 | 38 | }) |