generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefs.js
More file actions
59 lines (51 loc) · 972 Bytes
/
refs.js
File metadata and controls
59 lines (51 loc) · 972 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let n = 0;
export class RegistryKey extends String {
#stack = new DisposableStack();
/**
* @returns {boolean}
*/
get disposed() {
return this.#stack.disposed;
}
/**
* @template T
* @param {T} what
* @param {() => void} onDiposed
* @returns {T}
*/
adopt(what, onDiposed) {
return this.#stack.adopt(what, onDiposed);
}
/**
* @param {() => void} onDiposed
* @returns {void}
*/
defer(onDiposed) {
return this.#stack.defer(onDiposed);
}
/**
* @returns {void}
*/
dispose() {
this.#stack.dispose();
}
/**
* @template T
* @param {T} what
* @returns {T}
*/
use(what) {
return this.#stack.use(what);
}
[Symbol.dispose]() {
this.#stack.dispose();
}
}
/**
*
* @param {string} [prefix="ref-"]
* @param {number} [suffix=Date.now()]
* @returns {RegistryKey}
*/
export const getRef = (prefix = 'ref', suffix = Date.now()) => new RegistryKey(`${prefix}-${n++}-${suffix.toString(16)}`);
export const $ref = getRef;