-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnombo-worker-bootstrap.node.js
More file actions
60 lines (50 loc) · 1.32 KB
/
nombo-worker-bootstrap.node.js
File metadata and controls
60 lines (50 loc) · 1.32 KB
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
60
var Worker = require('./nombo-worker.node');
var worker;
var handleError = function (err) {
var error;
if (err.stack) {
error = {
message: err.message,
stack: err.stack
}
} else {
error = err;
}
process.send({type: 'error', data: error});
};
var handleNotice = function (notice) {
if (notice instanceof Error) {
notice = notice.message;
}
process.send({type: 'notice', data: notice});
};
var handleWorkerStart = function () {
process.send({type: 'ready'});
};
var handleExit = function () {
process.exit();
};
process.on('message', function (m) {
if (m.type == 'init') {
worker = new Worker(m.data);
if (m.data.propagateErrors) {
worker.on('error', handleError);
worker.on('notice', handleNotice);
worker.on(worker.EVENT_WORKER_START, handleWorkerStart);
worker.on(worker.EVENT_WORKER_EXIT, handleExit);
}
var workerController = require(m.data.paths.appWorkerControllerPath);
workerController.run(worker);
worker.start();
} else if (m.type == 'updateCache') {
worker.handleCacheUpdate(m.data.url, m.data.content, m.data.size);
} else if (m.type == 'updateCacheVersion') {
worker.handleCacheVersionUpdate(m.data.cacheVersion);
} else if (m.type == 'emit') {
if (m.data) {
worker.handleMasterEvent(m.event, m.data);
} else {
worker.handleMasterEvent(m.event);
}
}
});