mythix-orm 1.11.5 → 1.11.6

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.
@@ -1,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
- let globalAsyncStore;
4
-
5
- try {
6
- const { AsyncLocalStorage } = require('async_hooks');
7
- globalAsyncStore = new AsyncLocalStorage();
8
- } catch (error) {
9
- globalAsyncStore = {
10
- getStore: () => undefined,
11
- run: (context, callback) => callback(),
12
- };
3
+ let globalAsyncStore = global._mythixGlobalAsyncLocalStore;
4
+
5
+ if (!globalAsyncStore) {
6
+ try {
7
+ const { AsyncLocalStorage } = require('async_hooks');
8
+ global._mythixGlobalAsyncLocalStore = globalAsyncStore = new AsyncLocalStorage();
9
+ } catch (error) {
10
+ global._mythixGlobalAsyncLocalStore = globalAsyncStore = {
11
+ getStore: () => undefined,
12
+ run: (context, callback) => callback(),
13
+ };
14
+ }
13
15
  }
14
16
 
15
17
  function getContextStore() {
@@ -40,16 +42,13 @@ function setContextValue(key, value) {
40
42
  }
41
43
 
42
44
  function runInContext(context, callback) {
43
- return new Promise((resolve, reject) => {
44
- globalAsyncStore.run({ parent: globalAsyncStore.getStore(), context }, async () => {
45
- try {
46
- let result = await callback();
47
- resolve(result);
48
- } catch (error) {
49
- reject(error);
50
- }
51
- });
52
- });
45
+ return globalAsyncStore.run(
46
+ {
47
+ parent: globalAsyncStore.getStore(),
48
+ context,
49
+ },
50
+ callback,
51
+ );
53
52
  }
54
53
 
55
54
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm",
3
- "version": "1.11.5",
3
+ "version": "1.11.6",
4
4
  "description": "ORM for Mythix framework",
5
5
  "main": "lib/index",
6
6
  "type": "commonjs",