koa
Advanced tools
Comparing version 2.13.4 to 2.14.0
2.14.0 / 2022-12-06 | ||
================== | ||
**features** | ||
* [[`a293122`](http://github.com/koajs/koa/commit/a29312212839c6f0418152d2a2cd3bf3fd3ee5e4)] - feat: support asyncLocalStorage (#1721) (fengmk2 <<fengmk2@gmail.com>>) | ||
2.13.4 / 2021-10-19 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -11,2 +11,3 @@ | ||
const onFinished = require('on-finished'); | ||
const assert = require('assert'); | ||
const response = require('./response'); | ||
@@ -68,2 +69,8 @@ const compose = require('koa-compose'); | ||
} | ||
if (options.asyncLocalStorage) { | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
assert(AsyncLocalStorage, 'Requires node 12.17.0 or higher to enable asyncLocalStorage'); | ||
this.ctxStorage = new AsyncLocalStorage(); | ||
this.use(createAsyncCtxStorage(this)); | ||
} | ||
} | ||
@@ -159,2 +166,9 @@ | ||
/** | ||
* return currnect contenxt from async local storage | ||
*/ | ||
get currentContext() { | ||
if (this.ctxStorage) return this.ctxStorage.getStore(); | ||
} | ||
/** | ||
* Handle request in callback. | ||
@@ -228,2 +242,10 @@ * | ||
function createAsyncCtxStorage(app) { | ||
return async function asyncCtxStorage(ctx, next) { | ||
await app.ctxStorage.run(ctx, async() => { | ||
return await next(); | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -230,0 +252,0 @@ * Response helper. |
{ | ||
"name": "koa", | ||
"version": "2.13.4", | ||
"version": "2.14.0", | ||
"description": "Koa web app framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/application.js", |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
94806
1612
3