@@ -20,13 +20,11 @@ NestJS itself does not provide any built-in abstraction for `AsyncLocalStorage`,
20
20
import { AsyncLocalStorage } from ' async_hooks' ;
21
21
import { Module } from ' @nestjs/core' ;
22
22
23
- export const asyncLocalStorage = new AsyncLocalStorage ();
24
-
25
23
@Module ({
26
24
providers: [
27
25
{
28
26
provide: AsyncLocalStorage ,
29
- useValue: asyncLocalStorage ,
27
+ useValue: new AsyncLocalStorage () ,
30
28
},
31
29
],
32
30
exports: [AsyncLocalStorage ],
@@ -41,7 +39,7 @@ export class AlsModule {}
41
39
42
40
import { NestFactory } from ' @nestjs/core' ;
43
41
import { AppModule } from ' ./app.module' ;
44
- import { asyncLocalStorage } from ' ./als.setup .ts' ;
42
+ import { AsyncLocalStorage } from ' ./als.module .ts' ;
45
43
46
44
async function bootstrap() {
47
45
const app = await NestFactory .create (AppModule );
@@ -57,7 +55,7 @@ async function bootstrap() {
57
55
const store = {
58
56
userId: req .headers [' x-user-id' ],
59
57
};
60
- // and and pass the "next" function as callback
58
+ // and pass the "next" function as callback
61
59
// to the "als.run" method together with the store.
62
60
als .run (store , () => next ());
63
61
});
@@ -209,7 +207,7 @@ describe('CatService', () => {
209
207
(id ) => ({ userId: id })
210
208
)
211
209
212
- // Wrap the test call the `runWith` method
210
+ // Wrap the test call in the `runWith` method
213
211
// in which we can pass hand-crafted store values.
214
212
const cat = await cls .runWith (
215
213
{ userId: expectedUserId },
0 commit comments