ms-types 0.3.18 → 0.3.20
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/package.json
CHANGED
package/types/global.d.ts
CHANGED
|
@@ -58,10 +58,29 @@ declare const __package__: {
|
|
|
58
58
|
[key: string]: any;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
declare const sharedState: {
|
|
62
|
+
/**
|
|
63
|
+
* 设置共享状态
|
|
64
|
+
* @param key 状态键
|
|
65
|
+
* @param value 状态值
|
|
66
|
+
*/
|
|
67
|
+
set: (key: string, value: any) => void;
|
|
68
|
+
/**
|
|
69
|
+
* 获取共享状态
|
|
70
|
+
* @param key 状态键
|
|
71
|
+
* @returns 状态值
|
|
72
|
+
*/
|
|
73
|
+
get: (key: string) => any;
|
|
74
|
+
/**
|
|
75
|
+
* 批量操作共享状态
|
|
76
|
+
* @param block 批量操作代码块
|
|
77
|
+
*/
|
|
78
|
+
withBatch: (block: () => void) => void;
|
|
79
|
+
/**
|
|
80
|
+
* 清除所有共享状态
|
|
81
|
+
*/
|
|
82
|
+
clear: () => void;
|
|
83
|
+
};
|
|
65
84
|
|
|
66
85
|
/**
|
|
67
86
|
* 设置停止回调(仅主线程调用)
|
package/types/thread.d.ts
CHANGED
|
@@ -1,96 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 线程模块
|
|
2
|
+
* 线程模块
|
|
3
3
|
*/
|
|
4
4
|
declare namespace thread {
|
|
5
|
-
|
|
6
|
-
* 异步执行线程代码
|
|
7
|
-
* @param threadJsFile 线程js文件路径
|
|
8
|
-
* @param callbackName 回调函数名称
|
|
9
|
-
* @param callbackFunc 回调函数
|
|
10
|
-
* @returns 线程名称
|
|
11
|
-
* @example
|
|
12
|
-
* thread.execCodeAsync("thread.js", "callback", (data) => {
|
|
13
|
-
* logi(data)
|
|
14
|
-
* return "1111"
|
|
15
|
-
* })
|
|
16
|
-
*
|
|
17
|
-
* thread.js
|
|
18
|
-
* while (true) {
|
|
19
|
-
* // 通知主线程并传递数据
|
|
20
|
-
* const data = thread.invokeCallback("callback", "hello world")
|
|
21
|
-
* // 主线程返回数据
|
|
22
|
-
* logi(data)
|
|
23
|
-
* sleep(1000)
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
function execCodeAsync(
|
|
27
|
-
threadJsFile: string,
|
|
28
|
-
callbackName: string,
|
|
29
|
-
callbackFunc: (data?: any) => any
|
|
30
|
-
): string | null;
|
|
31
|
-
/**
|
|
32
|
-
* 调用线程回调函数
|
|
33
|
-
* @param name 回调函数名称
|
|
34
|
-
* @param data 回调数据
|
|
35
|
-
* @returns 回调返回值
|
|
36
|
-
* @example
|
|
37
|
-
* const data = thread.invokeCallback("callback", "hello world")
|
|
38
|
-
* logi(data)
|
|
39
|
-
*/
|
|
40
|
-
function invokeCallback(name: string, data?: any): any;
|
|
41
|
-
/**
|
|
42
|
-
* 创建新线程
|
|
43
|
-
* @param threadJsFile 线程js文件路径
|
|
44
|
-
* @returns 线程对象
|
|
45
|
-
* @example
|
|
46
|
-
* const newThread = thread.newThread("thread.js")
|
|
47
|
-
* newThread.addCallback("callback", (data) => {
|
|
48
|
-
* logi(data)
|
|
49
|
-
* return "1111"
|
|
50
|
-
* })
|
|
51
|
-
*/
|
|
52
|
-
function newThread(threadJsFile: string): {
|
|
5
|
+
class Thread {
|
|
53
6
|
/**
|
|
54
7
|
* 线程名称
|
|
55
8
|
*/
|
|
56
9
|
name: string;
|
|
57
10
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @param callbackFunc 回调函数
|
|
61
|
-
* @returns 是否添加成功
|
|
11
|
+
* 取消线程
|
|
12
|
+
* @returns 是否取消成功
|
|
62
13
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* return "1111"
|
|
77
|
-
* })
|
|
78
|
-
* thread.cancelThread(newThread.name)
|
|
79
|
-
*/
|
|
80
|
-
function cancelThread(name: string): boolean;
|
|
14
|
+
cancel: () => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 检查线程是否已取消
|
|
17
|
+
* @returns 是否已取消
|
|
18
|
+
*/
|
|
19
|
+
isCancelled: () => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 检查线程是否正在执行
|
|
22
|
+
* @returns 是否正在执行
|
|
23
|
+
*/
|
|
24
|
+
isExecuting: () => boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
81
27
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @returns
|
|
28
|
+
* 异步执行线程代码
|
|
29
|
+
* @param threadFunc 线程函数
|
|
30
|
+
* @returns 线程对象
|
|
85
31
|
* @example
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* logi(data)
|
|
89
|
-
* return "1111"
|
|
32
|
+
* thread.run(() => {
|
|
33
|
+
* logi("hello world")
|
|
90
34
|
* })
|
|
91
|
-
* thread.isCancelled(newThread.name)
|
|
92
35
|
*/
|
|
93
|
-
function
|
|
36
|
+
function run(threadFunc: () => void): Thread;
|
|
94
37
|
/**
|
|
95
38
|
* 停止所有线程
|
|
96
39
|
* @returns 是否停止成功
|
|
@@ -46,10 +46,29 @@ declare const $脚本配置: {
|
|
|
46
46
|
[key: 字符串]: 任意类型;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
declare const $共享状态: {
|
|
50
|
+
/**
|
|
51
|
+
* 设置共享状态
|
|
52
|
+
* @param key 状态键
|
|
53
|
+
* @param value 状态值
|
|
54
|
+
*/
|
|
55
|
+
设置: (key: 字符串, value: 任意类型) => 无返回值;
|
|
56
|
+
/**
|
|
57
|
+
* 获取共享状态
|
|
58
|
+
* @param key 状态键
|
|
59
|
+
* @returns 状态值
|
|
60
|
+
*/
|
|
61
|
+
获取: (key: 字符串) => 任意类型;
|
|
62
|
+
/**
|
|
63
|
+
* 批量操作共享状态
|
|
64
|
+
* @param block 批量操作代码块
|
|
65
|
+
*/
|
|
66
|
+
批量操作: (block: () => 无返回值) => 无返回值;
|
|
67
|
+
/**
|
|
68
|
+
* 清除所有共享状态
|
|
69
|
+
*/
|
|
70
|
+
清除所有共享状态: () => 无返回值;
|
|
71
|
+
};
|
|
53
72
|
|
|
54
73
|
/**
|
|
55
74
|
* 设置停止回调(仅主线程调用)
|
|
@@ -3,97 +3,42 @@
|
|
|
3
3
|
* 线程模块 包含线程操作、线程回调等功能
|
|
4
4
|
*/
|
|
5
5
|
declare namespace $线程 {
|
|
6
|
-
|
|
7
|
-
* 异步执行线程代码
|
|
8
|
-
* @param 线程js文件路径
|
|
9
|
-
* @param 回调函数名称
|
|
10
|
-
* @param 回调函数
|
|
11
|
-
* @returns 线程名称
|
|
12
|
-
* @example
|
|
13
|
-
* const 线程名称 = $线程.执行异步代码("xxx_thread.js", "回调函数名称", (数据) => {
|
|
14
|
-
* $打印信息日志(数据)
|
|
15
|
-
* return "1111"
|
|
16
|
-
* })
|
|
17
|
-
*
|
|
18
|
-
* thread.js
|
|
19
|
-
* while (true) {
|
|
20
|
-
* // 通知主线程并传递数据
|
|
21
|
-
* const 回调返回值 = $线程.调用回调函数("回调函数名称", "hello world")
|
|
22
|
-
* // 主线程返回数据
|
|
23
|
-
* $打印信息日志(回调返回值)
|
|
24
|
-
* $延时(1000)
|
|
25
|
-
* }
|
|
26
|
-
*/
|
|
27
|
-
function 执行异步代码(
|
|
28
|
-
线程js文件路径: 字符串,
|
|
29
|
-
回调函数名称: 字符串,
|
|
30
|
-
回调函数: (数据?: 任意类型) => 任意类型
|
|
31
|
-
): 字符串 | null;
|
|
32
|
-
/**
|
|
33
|
-
* 调用线程回调函数
|
|
34
|
-
* @param name 回调函数名称
|
|
35
|
-
* @param data 回调数据
|
|
36
|
-
* @returns 回调返回值
|
|
37
|
-
* @example
|
|
38
|
-
* const 回调返回值 = $线程.调用回调函数("回调函数名称", "hello world")
|
|
39
|
-
* $打印信息日志(回调返回值)
|
|
40
|
-
*/
|
|
41
|
-
function 调用回调函数(回调函数名称: 字符串, 数据?: 任意类型): 任意类型;
|
|
42
|
-
/**
|
|
43
|
-
* 创建新线程
|
|
44
|
-
* @param 线程js文件路径
|
|
45
|
-
* @returns 线程对象
|
|
46
|
-
* @example
|
|
47
|
-
* const 新线程 = $线程.创建新线程("xxx_thread.js")
|
|
48
|
-
* 新线程.添加回调函数("callback", (数据) => {
|
|
49
|
-
* $打印信息日志(数据)
|
|
50
|
-
* return "1111"
|
|
51
|
-
* })
|
|
52
|
-
*/
|
|
53
|
-
function 创建新线程(线程js文件路径: 字符串): {
|
|
6
|
+
class 线程 {
|
|
54
7
|
/**
|
|
55
8
|
* 线程名称
|
|
56
9
|
*/
|
|
57
|
-
|
|
10
|
+
线程名称: 字符串;
|
|
58
11
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
61
|
-
* @param 回调函数
|
|
62
|
-
* @returns 是否添加成功
|
|
12
|
+
* 取消线程
|
|
13
|
+
* @returns 是否取消成功
|
|
63
14
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* return "1111"
|
|
78
|
-
* })
|
|
79
|
-
* $线程.取消线程(新线程.name)
|
|
80
|
-
*/
|
|
81
|
-
function 取消线程(线程名称: 字符串): 布尔值;
|
|
15
|
+
取消: () => 布尔值;
|
|
16
|
+
/**
|
|
17
|
+
* 检查线程是否已取消
|
|
18
|
+
* @returns 是否已取消
|
|
19
|
+
*/
|
|
20
|
+
是否已取消: () => 布尔值;
|
|
21
|
+
/**
|
|
22
|
+
* 检查线程是否正在执行
|
|
23
|
+
* @returns 是否正在执行
|
|
24
|
+
*/
|
|
25
|
+
是否正在执行: () => 布尔值;
|
|
26
|
+
}
|
|
27
|
+
|
|
82
28
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @
|
|
29
|
+
* 异步执行线程代码
|
|
30
|
+
* @param 线程js文件路径
|
|
31
|
+
* @param 回调函数名称
|
|
32
|
+
* @param 回调函数
|
|
33
|
+
* @returns 线程名称
|
|
86
34
|
* @example
|
|
87
|
-
* const
|
|
88
|
-
*
|
|
89
|
-
* $打印信息日志(数据)
|
|
90
|
-
* return "1111"
|
|
35
|
+
* const 线程名称 = $线程.运行(() => {
|
|
36
|
+
* $打印信息日志("hello world")
|
|
91
37
|
* })
|
|
92
|
-
* $线程.是否已被取消(新线程.name)
|
|
93
38
|
*/
|
|
94
|
-
function
|
|
39
|
+
function 运行(线程函数: () => 无返回值): 线程;
|
|
95
40
|
/**
|
|
96
|
-
*
|
|
41
|
+
* 停止所有线程
|
|
97
42
|
* @returns 是否停止成功
|
|
98
43
|
* @example
|
|
99
44
|
* $线程.停止所有()
|