@gjsify/async_hooks 0.3.13 → 0.3.14

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.
Files changed (2) hide show
  1. package/lib/esm/index.js +122 -129
  2. package/package.json +4 -4
package/lib/esm/index.js CHANGED
@@ -1,138 +1,131 @@
1
+ //#region src/index.ts
1
2
  let _id = 1;
2
3
  function executionAsyncId() {
3
- return _id;
4
+ return _id;
4
5
  }
5
6
  function triggerAsyncId() {
6
- return 0;
7
+ return 0;
7
8
  }
8
9
  function createHook(_callbacks) {
9
- return {
10
- enable() {
11
- return this;
12
- },
13
- disable() {
14
- return this;
15
- }
16
- };
10
+ return {
11
+ enable() {
12
+ return this;
13
+ },
14
+ disable() {
15
+ return this;
16
+ }
17
+ };
17
18
  }
18
- class AsyncResource {
19
- _type;
20
- _asyncId;
21
- _triggerAsyncId;
22
- constructor(type, triggerAsyncIdOrOpts) {
23
- this._type = type;
24
- this._asyncId = _id++;
25
- if (typeof triggerAsyncIdOrOpts === "number") {
26
- this._triggerAsyncId = triggerAsyncIdOrOpts;
27
- } else if (triggerAsyncIdOrOpts && typeof triggerAsyncIdOrOpts.triggerAsyncId === "number") {
28
- this._triggerAsyncId = triggerAsyncIdOrOpts.triggerAsyncId;
29
- } else {
30
- this._triggerAsyncId = executionAsyncId();
31
- }
32
- }
33
- runInAsyncScope(fn, thisArg, ...args) {
34
- return fn.apply(thisArg, args);
35
- }
36
- emitDestroy() {
37
- return this;
38
- }
39
- asyncId() {
40
- return this._asyncId;
41
- }
42
- triggerAsyncId() {
43
- return this._triggerAsyncId;
44
- }
45
- bind(fn) {
46
- return ((...args) => {
47
- return this.runInAsyncScope(fn, void 0, ...args);
48
- });
49
- }
50
- static bind(fn, type) {
51
- const resource = new AsyncResource(type || fn.name || "bound-anonymous-fn");
52
- return resource.bind(fn);
53
- }
54
- }
55
- const _allInstances = /* @__PURE__ */ new Set();
56
- class AsyncLocalStorage {
57
- _store;
58
- constructor() {
59
- _allInstances.add(this);
60
- }
61
- getStore() {
62
- return this._store;
63
- }
64
- run(store, callback, ...args) {
65
- const prev = this._store;
66
- this._store = store;
67
- try {
68
- const result = callback(...args);
69
- if (result != null && typeof result.then === "function") {
70
- return result.then(
71
- (value) => {
72
- this._store = prev;
73
- return value;
74
- },
75
- (err) => {
76
- this._store = prev;
77
- throw err;
78
- }
79
- );
80
- }
81
- this._store = prev;
82
- return result;
83
- } catch (err) {
84
- this._store = prev;
85
- throw err;
86
- }
87
- }
88
- exit(callback, ...args) {
89
- const prev = this._store;
90
- this._store = void 0;
91
- try {
92
- return callback(...args);
93
- } finally {
94
- this._store = prev;
95
- }
96
- }
97
- enterWith(store) {
98
- this._store = store;
99
- }
100
- disable() {
101
- this._store = void 0;
102
- }
103
- static snapshot() {
104
- const captured = /* @__PURE__ */ new Map();
105
- for (const instance of _allInstances) {
106
- captured.set(instance, instance.getStore());
107
- }
108
- return (fn, ...args) => {
109
- const saved = /* @__PURE__ */ new Map();
110
- for (const [instance, store] of captured) {
111
- saved.set(instance, instance.getStore());
112
- instance._store = store;
113
- }
114
- try {
115
- return fn(...args);
116
- } finally {
117
- for (const [instance, store] of saved) {
118
- instance._store = store;
119
- }
120
- }
121
- };
122
- }
123
- }
124
- var index_default = {
125
- executionAsyncId,
126
- triggerAsyncId,
127
- createHook,
128
- AsyncResource,
129
- AsyncLocalStorage
19
+ var AsyncResource = class AsyncResource {
20
+ _type;
21
+ _asyncId;
22
+ _triggerAsyncId;
23
+ constructor(type, triggerAsyncIdOrOpts) {
24
+ this._type = type;
25
+ this._asyncId = _id++;
26
+ if (typeof triggerAsyncIdOrOpts === "number") {
27
+ this._triggerAsyncId = triggerAsyncIdOrOpts;
28
+ } else if (triggerAsyncIdOrOpts && typeof triggerAsyncIdOrOpts.triggerAsyncId === "number") {
29
+ this._triggerAsyncId = triggerAsyncIdOrOpts.triggerAsyncId;
30
+ } else {
31
+ this._triggerAsyncId = executionAsyncId();
32
+ }
33
+ }
34
+ runInAsyncScope(fn, thisArg, ...args) {
35
+ return fn.apply(thisArg, args);
36
+ }
37
+ emitDestroy() {
38
+ return this;
39
+ }
40
+ asyncId() {
41
+ return this._asyncId;
42
+ }
43
+ triggerAsyncId() {
44
+ return this._triggerAsyncId;
45
+ }
46
+ bind(fn) {
47
+ return ((...args) => {
48
+ return this.runInAsyncScope(fn, undefined, ...args);
49
+ });
50
+ }
51
+ static bind(fn, type) {
52
+ const resource = new AsyncResource(type || fn.name || "bound-anonymous-fn");
53
+ return resource.bind(fn);
54
+ }
55
+ };
56
+ const _allInstances = new Set();
57
+ var AsyncLocalStorage = class {
58
+ _store;
59
+ constructor() {
60
+ _allInstances.add(this);
61
+ }
62
+ getStore() {
63
+ return this._store;
64
+ }
65
+ run(store, callback, ...args) {
66
+ const prev = this._store;
67
+ this._store = store;
68
+ try {
69
+ const result = callback(...args);
70
+ if (result != null && typeof result.then === "function") {
71
+ return result.then((value) => {
72
+ this._store = prev;
73
+ return value;
74
+ }, (err) => {
75
+ this._store = prev;
76
+ throw err;
77
+ });
78
+ }
79
+ this._store = prev;
80
+ return result;
81
+ } catch (err) {
82
+ this._store = prev;
83
+ throw err;
84
+ }
85
+ }
86
+ exit(callback, ...args) {
87
+ const prev = this._store;
88
+ this._store = undefined;
89
+ try {
90
+ return callback(...args);
91
+ } finally {
92
+ this._store = prev;
93
+ }
94
+ }
95
+ enterWith(store) {
96
+ this._store = store;
97
+ }
98
+ disable() {
99
+ this._store = undefined;
100
+ }
101
+ static snapshot() {
102
+ const captured = new Map();
103
+ for (const instance of _allInstances) {
104
+ captured.set(instance, instance.getStore());
105
+ }
106
+ return (fn, ...args) => {
107
+ const saved = new Map();
108
+ for (const [instance, store] of captured) {
109
+ saved.set(instance, instance.getStore());
110
+ instance._store = store;
111
+ }
112
+ try {
113
+ return fn(...args);
114
+ } finally {
115
+ for (const [instance, store] of saved) {
116
+ instance._store = store;
117
+ }
118
+ }
119
+ };
120
+ }
130
121
  };
131
- export {
132
- AsyncLocalStorage,
133
- AsyncResource,
134
- createHook,
135
- index_default as default,
136
- executionAsyncId,
137
- triggerAsyncId
122
+ var src_default = {
123
+ executionAsyncId,
124
+ triggerAsyncId,
125
+ createHook,
126
+ AsyncResource,
127
+ AsyncLocalStorage
138
128
  };
129
+
130
+ //#endregion
131
+ export { AsyncLocalStorage, AsyncResource, createHook, src_default as default, executionAsyncId, triggerAsyncId };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/async_hooks",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Node.js async_hooks module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -30,11 +30,11 @@
30
30
  "async_hooks"
31
31
  ],
32
32
  "dependencies": {
33
- "@gjsify/events": "^0.3.13"
33
+ "@gjsify/events": "^0.3.14"
34
34
  },
35
35
  "devDependencies": {
36
- "@gjsify/cli": "^0.3.13",
37
- "@gjsify/unit": "^0.3.13",
36
+ "@gjsify/cli": "^0.3.14",
37
+ "@gjsify/unit": "^0.3.14",
38
38
  "@types/node": "^25.6.0",
39
39
  "typescript": "^6.0.3"
40
40
  }