koa 3.1.2 → 3.2.0
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 +0 -8
- package/lib/application.js +14 -3
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -189,14 +189,6 @@ See [AUTHORS](AUTHORS).
|
|
|
189
189
|
- [中文文档 v2.x](https://github.com/demopark/koa-docs-Zh-CN)
|
|
190
190
|
- __[#koajs]__ on freenode
|
|
191
191
|
|
|
192
|
-
## Job Board
|
|
193
|
-
|
|
194
|
-
Looking for a career upgrade?
|
|
195
|
-
|
|
196
|
-
<a href="https://astro.netlify.com/automattic"><img src="https://astro.netlify.com/static/automattic.png"></a>
|
|
197
|
-
<a href="https://astro.netlify.com/segment"><img src="https://astro.netlify.com/static/segment.png"></a>
|
|
198
|
-
<a href="https://astro.netlify.com/auth0"><img src="https://astro.netlify.com/static/auth0.png"/></a>
|
|
199
|
-
|
|
200
192
|
## Backers
|
|
201
193
|
|
|
202
194
|
Support us with a monthly donation and help us continue our activities.
|
package/lib/application.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
const util = require('node:util')
|
|
7
|
+
const v8 = require('node:v8')
|
|
7
8
|
const debug = util.debuglog('koa:application')
|
|
8
9
|
const Emitter = require('node:events')
|
|
9
10
|
const Stream = require('node:stream')
|
|
@@ -40,6 +41,13 @@ const only = require('./only.js')
|
|
|
40
41
|
* Inherits from `Emitter.prototype`.
|
|
41
42
|
*/
|
|
42
43
|
|
|
44
|
+
function getAsyncLocalStorage (options) {
|
|
45
|
+
if (options.asyncLocalStorage instanceof AsyncLocalStorage) {
|
|
46
|
+
return options.asyncLocalStorage
|
|
47
|
+
}
|
|
48
|
+
return new AsyncLocalStorage()
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
module.exports = class Application extends Emitter {
|
|
44
52
|
/**
|
|
45
53
|
* Initialize a new `Application`.
|
|
@@ -81,10 +89,13 @@ module.exports = class Application extends Emitter {
|
|
|
81
89
|
this[util.inspect.custom] = this.inspect
|
|
82
90
|
}
|
|
83
91
|
if (options.asyncLocalStorage) {
|
|
84
|
-
if (
|
|
85
|
-
this.ctxStorage =
|
|
92
|
+
if (v8.startupSnapshot?.isBuildingSnapshot?.()) {
|
|
93
|
+
this.ctxStorage = null
|
|
94
|
+
v8.startupSnapshot.addDeserializeCallback(({ app, options }) => {
|
|
95
|
+
app.ctxStorage = getAsyncLocalStorage(options)
|
|
96
|
+
}, { app: this, options })
|
|
86
97
|
} else {
|
|
87
|
-
this.ctxStorage =
|
|
98
|
+
this.ctxStorage = getAsyncLocalStorage(options)
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
}
|