Skip to content

Commit e82256b

Browse files
committedDec 24, 2019
[ADD] add test & serve code and make sure api
1 parent 28fcb84 commit e82256b

File tree

8 files changed

+537
-12
lines changed

8 files changed

+537
-12
lines changed
 

‎dist/index.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<title>Document</title>
8-
<script src="./BetterWorker.min.js"></script>
98
</head>
109
<body>
11-
10+
<h1>test betterworker</h1>
1211
</body>
13-
</html>
12+
</html>
13+
<script src="./BetterWorker.min.js"></script>
14+
<script type="text/javascript">
15+
16+
</script>

‎package-lock.json

+463
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"devDependencies": {
2222
"@babel/core": "^7.7.2",
23+
"express": "^4.17.1",
2324
"rollup": "^1.26.3",
2425
"rollup-plugin-babel": "^4.3.3",
2526
"rollup-plugin-commonjs": "^10.1.0",

‎src/index.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ import { ThreadManager, ThreadManagerConfig} from './thread/thread-manager';
33
class BetterWorker {
44
private option: any;
55
private tm: ThreadManager;
6-
public doTask(option: any) {
7-
this.option = option;
8-
this.tm = new ThreadManager(option.threadConfig, option.workerConfig);
6+
constructor(workerPaths: Array<string>) {
7+
98
}
109

11-
public close(): void {
12-
13-
}
14-
15-
public destory(): void {
16-
10+
public doTask(index: Number, method: string, param: any, listener: Function) {
11+
1712
}
1813
}
1914

‎src/server/server.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var express = require('express');
2+
var app = express();
3+
let count = 1;
4+
app.get('/test', function(request, response) {
5+
count += 1;
6+
var data = {
7+
number: count,
8+
};
9+
response.header("Access-Control-Allow-Origin", "*");
10+
response.write(JSON.stringify(data));
11+
response.end();
12+
});
13+
14+
app.listen('8010', function() {
15+
console.log("server start success, port is 8010");
16+
});

‎src/thread/thread-factory.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export class ThreadFactory implements ThreadFactoryI {
88
window.fetch(url).then(response => response.text()).then(res => {
99
const worker = new window.Worker(window.URL.createObjectURL(new window.Blob([res])));
1010
ok(worker);
11+
}).then(error => {
12+
no(error);
1113
});
1214
});
1315
}

‎test/index.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>test betterworker</h1>
11+
</body>
12+
</html>
13+
<script src="./request.js"></script>
14+
<script src="./BetterWorker.min.js"></script>
15+
<script type="text/javascript">
16+
// const api = 'http://127.0.0.1:8010/test';
17+
// request(api);
18+
const api = 'http://127.0.0.1:8018/test';
19+
const workerPath = 'http://local.h5.com/mygithub/better-webworker/test/request.js';
20+
const bw = new BetterWorker([
21+
workerPath,
22+
workerPath,
23+
workerPath,
24+
workerPath,
25+
]);
26+
bw.doTask(0, 'request', api, function(res) {
27+
28+
});
29+
bw.doTask(1, 'request', api, function(res) {
30+
31+
});
32+
bw.doTask(2, 'request', api, function(res) {
33+
34+
});
35+
bw.doTask(3, 'request', api, function(res) {
36+
37+
});
38+
</script>

‎test/request.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function request(api) {
2+
fetch(api).then(res => {
3+
return res.json();
4+
}).then((res) => {
5+
console.log(res);
6+
});
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.