-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.ts
33 lines (25 loc) · 829 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @adonisjs/http-server
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/// <reference path="../../adonis-typings/index.ts" />
import { AsyncLocalStorage } from 'async_hooks'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export let asyncHttpContextEnabled = false
export function setAsyncHttpContextEnabled(enabled: boolean) {
asyncHttpContextEnabled = enabled
}
export const adonisLocalStorage = new AsyncLocalStorage<AsyncHttpContext>()
export class AsyncHttpContext {
constructor(private ctx: HttpContextContract) {}
public getContext() {
return this.ctx
}
public run(callback: () => any) {
return adonisLocalStorage.run(this, callback)
}
}