@epic-js/express-profiler 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ POST /reverseGeoCoding 200 279.9ms
|
|
|
23
23
|
|
|
24
24
|
## After finding the slow routes dig deeper by using the wrapAsync
|
|
25
25
|
```js
|
|
26
|
+
// ----- Fast route -----
|
|
26
27
|
app.get('/users', async (req, res) => {
|
|
27
28
|
const users = await wrapAsync(async () => [{ id: 1, name: 'Alice' }], 'DB', req)();
|
|
28
29
|
res.send(users);
|
|
@@ -36,7 +37,10 @@ GET /users 200 1.4ms
|
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
## Usage
|
|
39
|
-
```
|
|
40
|
+
```js
|
|
41
|
+
const { wrapAsync } = require('@epic-js/express-profiler/wrappers');
|
|
42
|
+
|
|
43
|
+
// ----- Slow route -----
|
|
40
44
|
app.get('/slow', async (req, res) => {
|
|
41
45
|
const dbTask = wrapAsync(() => new Promise(r => setTimeout(r, 300)), 'DB', req);
|
|
42
46
|
const apiTask = wrapAsync(() => new Promise(r => setTimeout(r, 200)), 'External API', req);
|
|
@@ -51,6 +55,20 @@ GET /slow 200 518.3ms
|
|
|
51
55
|
DB: 309.1ms
|
|
52
56
|
External API: 203.9ms
|
|
53
57
|
```
|
|
58
|
+
```js
|
|
59
|
+
// ----- Slow route -----
|
|
60
|
+
app.get('/nested', async (req, res) => {
|
|
61
|
+
await wrapAsync(async () => {
|
|
62
|
+
await wrapAsync(() => new Promise(r => setTimeout(r, 100)), 'Inner DB', req)();
|
|
63
|
+
}, 'Outer wrapper', req)();
|
|
64
|
+
res.send('Nested async done');
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
```bash
|
|
68
|
+
GET /nested 200 111.3ms
|
|
69
|
+
Inner DB: 106.6ms
|
|
70
|
+
Outer wrapper: 106.6ms
|
|
71
|
+
```
|
|
54
72
|
|
|
55
73
|
## CLI Usage
|
|
56
74
|
```
|