@@ -166,7 +166,7 @@ class AsyncLocal<T = any> {
166
166
setValue(value: T);
167
167
}
168
168
169
- type ValueChangedListener< T > = (newValue: T , prevValue: T );
169
+ type ValueChangedListener< T > = (newValue : T , prevValue : T ) => void ;
170
170
` ` `
171
171
172
172
` AsyncLocal .getValue ()` returns the current value of the async execution flow.
@@ -312,7 +312,7 @@ query with the request trace id.
312
312
First we'll have a module holding the async local instance.
313
313
314
314
` ` ` js
315
- //
315
+ // context.js
316
316
const asyncLocal = new AsyncLocal ();
317
317
318
318
export function setContext (ctx ) {
@@ -324,14 +324,14 @@ export function getContext() {
324
324
}
325
325
` ` `
326
326
327
- With the our owned instance of async local, we can set the value on each
327
+ With our owned instance of async local, we can set the value on each
328
328
request handling call. After set the context, any operations afterwards can
329
329
fetch the context with the instance of async local.
330
330
331
331
` ` ` js
332
332
import { createServer } from ' http' ;
333
- import { setContext } from ' ./context' ;
334
- import { queryDatabase } from ' ./db' ;
333
+ import { setContext } from ' ./context.js ' ;
334
+ import { queryDatabase } from ' ./db.js ' ;
335
335
336
336
const server = createServer (handleRequest);
337
337
@@ -350,8 +350,8 @@ So we don't need an additional parameter to the database query functions.
350
350
Still, it's easy to fetch the request data and print it.
351
351
352
352
` ` ` js
353
- import { getContext } from ' ./context ' ;
354
- // some module
353
+ // db.js
354
+ import { getContext } from ' ./context.js ' ;
355
355
export function queryDatabase (query ) {
356
356
const ctx = getContext ();
357
357
console .log (' query database by request %o with query %o' ,
0 commit comments