wenay-common2 1.0.43 → 1.0.45
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/lib/Common/events/Listen.d.ts +23 -23
- package/lib/Common/events/Listen.js +15 -17
- package/lib/Common/events/SocketBuffer.d.ts +10 -4
- package/lib/Common/events/SocketServerHook.d.ts +12 -6
- package/lib/Common/events/UseListenTransform.d.ts +6 -3
- package/lib/Common/rcp/listen-socket.js +1 -1
- package/lib/Exchange/LoadBase.d.ts +2 -1
- package/lib/Exchange/LoadBase.js +6 -5
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type Listener<T extends any[]> = (...r: T) => void;
|
|
2
2
|
export type NormalizeTuple<T> = T extends any[] ? T : [T];
|
|
3
|
-
|
|
3
|
+
type key = string;
|
|
4
|
+
export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), { fast, event, addListenClose }?: {
|
|
4
5
|
event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void;
|
|
5
6
|
fast?: boolean;
|
|
6
7
|
addListenClose?: ReturnType<typeof funcListenCallbackBase<any>>;
|
|
@@ -10,11 +11,14 @@ export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple
|
|
|
10
11
|
run: () => void;
|
|
11
12
|
close: () => void;
|
|
12
13
|
eventClose: (cb: () => void) => () => void;
|
|
13
|
-
removeEventClose: (cb: () => void) => void;
|
|
14
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, cbClose
|
|
15
|
-
|
|
14
|
+
removeEventClose: (cb: (() => void)) => void;
|
|
15
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
16
|
+
cbClose?: () => void;
|
|
17
|
+
key?: key;
|
|
18
|
+
}) => () => void;
|
|
19
|
+
removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
|
|
16
20
|
count: () => number;
|
|
17
|
-
readonly getAllKeys: Listener<NormalizeTuple<T>>[];
|
|
21
|
+
readonly getAllKeys: (Listener<NormalizeTuple<T>> | key)[];
|
|
18
22
|
};
|
|
19
23
|
export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
|
|
20
24
|
func: Listener<NormalizeTuple<T>>;
|
|
@@ -23,23 +27,15 @@ export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTupl
|
|
|
23
27
|
close: () => void;
|
|
24
28
|
eventClose: (cb: () => void) => () => void;
|
|
25
29
|
removeEventClose: (cb: () => void) => void;
|
|
26
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, cbClose
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export declare function funcListenCallback<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void)), event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void, fast?: boolean): {
|
|
32
|
-
func: Listener<NormalizeTuple<T>>;
|
|
33
|
-
isRun: () => boolean;
|
|
34
|
-
run: () => void;
|
|
35
|
-
close: () => void;
|
|
36
|
-
eventClose: (cb: () => void) => () => void;
|
|
37
|
-
removeEventClose: (cb: () => void) => void;
|
|
38
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, cbClose?: (() => void) | undefined) => () => void;
|
|
39
|
-
removeListen: (cb: Listener<NormalizeTuple<T>> | null) => void;
|
|
30
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
31
|
+
cbClose?: (() => void) | undefined;
|
|
32
|
+
key?: key;
|
|
33
|
+
}) => () => void;
|
|
34
|
+
removeListen: (k: string | Listener<NormalizeTuple<T>> | null) => void;
|
|
40
35
|
count: () => number;
|
|
41
|
-
readonly getAllKeys: Listener<NormalizeTuple<T>>[];
|
|
36
|
+
readonly getAllKeys: (string | Listener<NormalizeTuple<T>>)[];
|
|
42
37
|
};
|
|
38
|
+
export declare const funcListenCallback: typeof funcListenCallbackBase;
|
|
43
39
|
export declare function UseListen<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, {
|
|
44
40
|
func: Listener<NormalizeTuple<T>>;
|
|
45
41
|
isRun: () => boolean;
|
|
@@ -47,9 +43,13 @@ export declare function UseListen<T>(data?: Parameters<typeof funcListenCallback
|
|
|
47
43
|
close: () => void;
|
|
48
44
|
eventClose: (cb: () => void) => () => void;
|
|
49
45
|
removeEventClose: (cb: () => void) => void;
|
|
50
|
-
addListen: (cb: Listener<NormalizeTuple<T>>, cbClose
|
|
51
|
-
|
|
46
|
+
addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
|
|
47
|
+
cbClose?: (() => void) | undefined;
|
|
48
|
+
key?: key;
|
|
49
|
+
}) => () => void;
|
|
50
|
+
removeListen: (k: string | Listener<NormalizeTuple<T>> | null) => void;
|
|
52
51
|
count: () => number;
|
|
53
|
-
readonly getAllKeys: Listener<NormalizeTuple<T>>[];
|
|
52
|
+
readonly getAllKeys: (string | Listener<NormalizeTuple<T>>)[];
|
|
54
53
|
}];
|
|
55
54
|
export declare function isListenCallback(obj: any): obj is ReturnType<typeof funcListenCallbackBase>;
|
|
55
|
+
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.funcListenCallback = void 0;
|
|
3
4
|
exports.funcListenCallbackBase = funcListenCallbackBase;
|
|
4
5
|
exports.funcListenCallbackFast = funcListenCallbackFast;
|
|
5
|
-
exports.funcListenCallback = funcListenCallback;
|
|
6
6
|
exports.UseListen = UseListen;
|
|
7
7
|
exports.isListenCallback = isListenCallback;
|
|
8
|
-
function funcListenCallbackBase(b,
|
|
9
|
-
const { fast = true, event, addListenClose } = data ?? {};
|
|
8
|
+
function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {}) {
|
|
10
9
|
const obj = new Map();
|
|
11
10
|
const evClose = new Map();
|
|
12
11
|
const sinh = new Map();
|
|
@@ -75,31 +74,32 @@ function funcListenCallbackBase(b, data) {
|
|
|
75
74
|
sinh.delete(cb);
|
|
76
75
|
evClose.delete(cb);
|
|
77
76
|
},
|
|
78
|
-
addListen: (cb, cbClose) => {
|
|
79
|
-
|
|
77
|
+
addListen: (cb, { cbClose, key } = {}) => {
|
|
78
|
+
const k = key ?? cb;
|
|
79
|
+
obj.set(k, cb);
|
|
80
80
|
if (cbClose) {
|
|
81
|
-
if (evClose.has(
|
|
82
|
-
const r = evClose.get(
|
|
81
|
+
if (evClose.has(k)) {
|
|
82
|
+
const r = evClose.get(k);
|
|
83
83
|
if (r !== cbClose) {
|
|
84
84
|
evClose.delete(r);
|
|
85
|
-
evClose.delete(
|
|
85
|
+
evClose.delete(k);
|
|
86
86
|
sinh.delete(r);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
evClose.set(
|
|
89
|
+
evClose.set(k, cbClose);
|
|
90
90
|
sinh.set(cbClose, cb);
|
|
91
91
|
}
|
|
92
92
|
if (fast)
|
|
93
93
|
rebuild();
|
|
94
94
|
event?.("add", obj.size, api);
|
|
95
|
-
return () => api.removeListen(
|
|
95
|
+
return () => api.removeListen(k);
|
|
96
96
|
},
|
|
97
|
-
removeListen: (
|
|
98
|
-
obj.delete(
|
|
99
|
-
const e = evClose.get(
|
|
97
|
+
removeListen: (k) => {
|
|
98
|
+
obj.delete(k);
|
|
99
|
+
const e = evClose.get(k);
|
|
100
100
|
if (fast)
|
|
101
101
|
rebuild();
|
|
102
|
-
evClose.delete(
|
|
102
|
+
evClose.delete(k);
|
|
103
103
|
if (e) {
|
|
104
104
|
evClose.delete(e);
|
|
105
105
|
sinh.delete(e);
|
|
@@ -114,9 +114,7 @@ function funcListenCallbackBase(b, data) {
|
|
|
114
114
|
function funcListenCallbackFast(a) {
|
|
115
115
|
return funcListenCallbackBase(a, { fast: true });
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
return funcListenCallbackBase(a, { event, fast });
|
|
119
|
-
}
|
|
117
|
+
exports.funcListenCallback = funcListenCallbackBase;
|
|
120
118
|
function UseListen(data = { fast: true }) {
|
|
121
119
|
let t;
|
|
122
120
|
const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
|
|
@@ -18,7 +18,10 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
|
|
|
18
18
|
memo: T4;
|
|
19
19
|
snapshot?: (memo: T4) => T3;
|
|
20
20
|
}): {
|
|
21
|
-
run: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>,
|
|
21
|
+
run: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, params_1?: {
|
|
22
|
+
cbClose?: (() => void) | undefined;
|
|
23
|
+
key?: string;
|
|
24
|
+
} | undefined) => () => void;
|
|
22
25
|
snapshot: () => T3 | undefined;
|
|
23
26
|
memo: T4;
|
|
24
27
|
listenA: {
|
|
@@ -28,10 +31,13 @@ export declare function funcListenCallbackSnapshot<T extends realSocket2<any | a
|
|
|
28
31
|
close: () => void;
|
|
29
32
|
eventClose: (cb: () => void) => () => void;
|
|
30
33
|
removeEventClose: (cb: () => void) => void;
|
|
31
|
-
addListen: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, cbClose
|
|
32
|
-
|
|
34
|
+
addListen: (cb: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>, { cbClose, key }?: {
|
|
35
|
+
cbClose?: (() => void) | undefined;
|
|
36
|
+
key?: string;
|
|
37
|
+
}) => () => void;
|
|
38
|
+
removeListen: (k: string | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]> | null) => void;
|
|
33
39
|
count: () => number;
|
|
34
|
-
readonly getAllKeys: import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>[];
|
|
40
|
+
readonly getAllKeys: (string | import("./Listen").Listener<[data: getTypeCallback<T>, memo: T3]>)[];
|
|
35
41
|
};
|
|
36
42
|
connect: () => void;
|
|
37
43
|
readonly disconnect: ((a: Omit<Parameters<T>[0], "callback"> & {
|
|
@@ -11,10 +11,13 @@ export declare function SocketServerHook(opt?: {
|
|
|
11
11
|
close: () => void;
|
|
12
12
|
eventClose: (cb: () => void) => () => void;
|
|
13
13
|
removeEventClose: (cb: () => void) => void;
|
|
14
|
-
addListen: (cb: import("./Listen").Listener<[unknown]>, cbClose
|
|
15
|
-
|
|
14
|
+
addListen: (cb: import("./Listen").Listener<[unknown]>, { cbClose, key }?: {
|
|
15
|
+
cbClose?: (() => void) | undefined;
|
|
16
|
+
key?: string;
|
|
17
|
+
}) => () => void;
|
|
18
|
+
removeListen: (k: string | import("./Listen").Listener<[unknown]> | null) => void;
|
|
16
19
|
count: () => number;
|
|
17
|
-
readonly getAllKeys: import("./Listen").Listener<[unknown]>[];
|
|
20
|
+
readonly getAllKeys: (string | import("./Listen").Listener<[unknown]>)[];
|
|
18
21
|
}];
|
|
19
22
|
};
|
|
20
23
|
get(tag: string): readonly [(a_0: unknown) => void, {
|
|
@@ -24,10 +27,13 @@ export declare function SocketServerHook(opt?: {
|
|
|
24
27
|
close: () => void;
|
|
25
28
|
eventClose: (cb: () => void) => () => void;
|
|
26
29
|
removeEventClose: (cb: () => void) => void;
|
|
27
|
-
addListen: (cb: import("./Listen").Listener<[unknown]>, cbClose
|
|
28
|
-
|
|
30
|
+
addListen: (cb: import("./Listen").Listener<[unknown]>, { cbClose, key }?: {
|
|
31
|
+
cbClose?: (() => void) | undefined;
|
|
32
|
+
key?: string;
|
|
33
|
+
}) => () => void;
|
|
34
|
+
removeListen: (k: string | import("./Listen").Listener<[unknown]> | null) => void;
|
|
29
35
|
count: () => number;
|
|
30
|
-
readonly getAllKeys: import("./Listen").Listener<[unknown]>[];
|
|
36
|
+
readonly getAllKeys: (string | import("./Listen").Listener<[unknown]>)[];
|
|
31
37
|
}];
|
|
32
38
|
provider: (tag: string, data: any) => void;
|
|
33
39
|
};
|
|
@@ -8,8 +8,11 @@ export declare function UseListenTransform<TSource extends any[], TTarget extend
|
|
|
8
8
|
close: () => void;
|
|
9
9
|
eventClose: (cb: () => void) => () => void;
|
|
10
10
|
removeEventClose: (cb: () => void) => void;
|
|
11
|
-
addListen: (cb: Listener<NormalizeTuple<TTarget>>, cbClose
|
|
12
|
-
|
|
11
|
+
addListen: (cb: Listener<NormalizeTuple<TTarget>>, { cbClose, key }?: {
|
|
12
|
+
cbClose?: (() => void) | undefined;
|
|
13
|
+
key?: string;
|
|
14
|
+
}) => () => void;
|
|
15
|
+
removeListen: (k: string | Listener<NormalizeTuple<TTarget>> | null) => void;
|
|
13
16
|
count: () => number;
|
|
14
|
-
readonly getAllKeys: Listener<NormalizeTuple<TTarget>>[];
|
|
17
|
+
readonly getAllKeys: (string | Listener<NormalizeTuple<TTarget>>)[];
|
|
15
18
|
}];
|
|
@@ -71,7 +71,7 @@ function listenSocket(e, d) {
|
|
|
71
71
|
}
|
|
72
72
|
inner(...a);
|
|
73
73
|
};
|
|
74
|
-
addListen(active, removeCallback);
|
|
74
|
+
addListen(active, { cbClose: removeCallback });
|
|
75
75
|
addListenClose?.addListen(removeCallback);
|
|
76
76
|
return new Promise((resolve) => {
|
|
77
77
|
resolveWait = () => { resolve(); };
|
package/lib/Exchange/LoadBase.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoadQuoteBase = LoadQuoteBase;
|
|
4
|
-
const wenay_common2_1 = require("wenay-common2");
|
|
5
4
|
const funcTimeWait_1 = require("../Common/funcTimeWait");
|
|
5
|
+
const Time_1 = require("../Common/Time");
|
|
6
|
+
const common_1 = require("../Common/core/common");
|
|
6
7
|
function LoadQuoteBase(setting, data) {
|
|
7
8
|
const { base, maxLoadBars, countConnect, intervalToName } = setting;
|
|
8
9
|
const maxLoadBars2 = setting.maxLoadBars2 ?? maxLoadBars;
|
|
@@ -15,7 +16,7 @@ function LoadQuoteBase(setting, data) {
|
|
|
15
16
|
const t1 = funcTimeWait_1.FuncTimeWait.byWeight(keyName, setting.countConnect) - (Date.now() - time) + 1;
|
|
16
17
|
if (t1 > 0) {
|
|
17
18
|
funcTimeWait_1.FuncTimeWait.add({ type: keyName, weight: weight, timeStamp: Date.now() + t1 });
|
|
18
|
-
await (0,
|
|
19
|
+
await (0, common_1.sleepAsync)(t1);
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
21
22
|
funcTimeWait_1.FuncTimeWait.add({ type: keyName, weight: weight, timeStamp: Date.now() });
|
|
@@ -136,7 +137,7 @@ function LoadQuoteBase(setting, data) {
|
|
|
136
137
|
async function test() {
|
|
137
138
|
const arr = [];
|
|
138
139
|
for (let i = 0; i < 10000; i++) {
|
|
139
|
-
arr[i] = { time: Date.now() - i *
|
|
140
|
+
arr[i] = { time: Date.now() - i * Time_1.TF.H1.msec, price: i };
|
|
140
141
|
}
|
|
141
142
|
let ress = [];
|
|
142
143
|
const tt = LoadQuoteBase({
|
|
@@ -150,14 +151,14 @@ async function test() {
|
|
|
150
151
|
nameKey: "cd",
|
|
151
152
|
maxLoadBars: 100,
|
|
152
153
|
time: 50,
|
|
153
|
-
intervalToName: [{ name: "1", time:
|
|
154
|
+
intervalToName: [{ name: "1", time: Time_1.TF.H1 }],
|
|
154
155
|
funcLoad: (data) => {
|
|
155
156
|
ress.push(data.startTime);
|
|
156
157
|
ress.push(data.endTime);
|
|
157
158
|
return (async () => [{ time: 5 }])();
|
|
158
159
|
}
|
|
159
160
|
});
|
|
160
|
-
const res = await tt({ symbol: "s", time2: new Date(), tf:
|
|
161
|
+
const res = await tt({ symbol: "s", time2: new Date(), tf: Time_1.TF.H1, time1: new Date(2015) });
|
|
161
162
|
ress.sort((a, b) => a.valueOf() - b.valueOf());
|
|
162
163
|
console.log(ress);
|
|
163
164
|
console.log(res);
|