nv-facutil-abt 1.0.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.
Files changed (2) hide show
  1. package/index.js +32 -0
  2. package/package.json +11 -0
package/index.js ADDED
@@ -0,0 +1,32 @@
1
+ const RESET_SYM = Symbol("reset");
2
+ class Aborter {
3
+ #nid = 1;
4
+ #sig = null;
5
+ #abt = null;
6
+ name = "";
7
+ [RESET_SYM]() {
8
+ let ac = new AbortController();
9
+ this.#sig = ac.signal;
10
+ let id = this.name +"/"+ Date.now()+"/"+ this.#nid;
11
+ this.#nid++; if(this.#nid === Number.MAX_SAFE_INTEGER) {this.#nid=1;}
12
+ ac.signal["#id"] = id;
13
+ let self = this;
14
+ this.#abt = ()=>{ac.abort();self[RESET_SYM]();}
15
+ this.#abt["#id"] = id;
16
+ }
17
+ constructor(name="") {this.name=name;this[RESET_SYM]()}
18
+ get sig() { return this.#sig;}
19
+ get abt() { return this.#abt;}
20
+ get id() { return this.#sig["#id"]}
21
+ get desc() {
22
+ let arr = this.id.split("/");
23
+ return({
24
+ name: arr[0],
25
+ time: new Date(Number(arr[1])),
26
+ seq : Number(arr[2])
27
+ })
28
+ }
29
+ }
30
+ const creat = (name)=>new Aborter(name);
31
+ module.exports = creat("");
32
+ module.exports.creat = creat;
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "nv-facutil-abt",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "author": "",
9
+ "license": "ISC",
10
+ "description": ""
11
+ }