pubo-node 1.0.129 → 1.0.136

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.
@@ -115,53 +115,160 @@ var __generator = this && this.__generator || function (thisArg, body) {
115
115
  };
116
116
  }
117
117
  };
118
+ var __values = this && this.__values || function (o) {
119
+ var s = typeof Symbol === "function" && Symbol.iterator,
120
+ m = s && o[s],
121
+ i = 0;
122
+ if (m) return m.call(o);
123
+ if (o && typeof o.length === "number") return {
124
+ next: function next() {
125
+ if (o && i >= o.length) o = void 0;
126
+ return {
127
+ value: o && o[i++],
128
+ done: !o
129
+ };
130
+ }
131
+ };
132
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
133
+ };
118
134
  Object.defineProperty(exports, "__esModule", {
119
135
  value: true
120
136
  });
121
- exports.SIGKILL = exports.isProcessDied = exports.getProcessName = void 0;
137
+ exports.SIGKILL = exports.getProcessTree = exports.getProcessByPpid = exports.isProcessDied = exports.getProcessCommandByPid = exports.getProcessCpuUseByPid = exports.getProcessName = void 0;
122
138
  var child_process_1 = require("child_process");
123
139
  var pubo_utils_1 = require("pubo-utils");
140
+ // 获取进程名称
124
141
  function getProcessName(pid) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- return __generator(this, function (_a) {
127
- return [2 /*return*/, new Promise(function (resolve) {
128
- var child = (0, child_process_1.exec)("grep \"Name:\" /proc/".concat(pid, "/status"));
129
- var resolved = false;
130
- var cb = function cb(data) {
131
- if (resolved) {
132
- return;
133
- }
134
- resolved = true;
135
- resolve(data);
136
- child = null;
137
- };
138
- child.stdout.on('data', function (data) {
139
- return cb(data.toString());
140
- });
141
- child.stderr.on('data', function (data) {
142
- return cb(data.toString());
143
- });
144
- })];
142
+ return new Promise(function (resolve, reject) {
143
+ (0, child_process_1.exec)("grep \"Name:\" /proc/".concat(pid, "/status"), function (err, data) {
144
+ if (err) {
145
+ reject(err);
146
+ } else {
147
+ resolve(data);
148
+ }
145
149
  });
146
150
  });
147
151
  }
148
152
  exports.getProcessName = getProcessName;
153
+ // 获取进程 cpu 使用率
154
+ function getProcessCpuUseByPid(pid) {
155
+ return new Promise(function (resolve) {
156
+ (0, child_process_1.exec)("ps -p ".concat(pid, " -o %cpu="), function (err, stdout) {
157
+ if (err) {
158
+ resolve(-1);
159
+ } else {
160
+ resolve(parseFloat(stdout.toString()));
161
+ }
162
+ });
163
+ });
164
+ }
165
+ exports.getProcessCpuUseByPid = getProcessCpuUseByPid;
166
+ // 获取进程 command 使用率
167
+ function getProcessCommandByPid(pid) {
168
+ return new Promise(function (resolve) {
169
+ (0, child_process_1.exec)("ps -p ".concat(pid, " -o command="), function (err, stdout) {
170
+ if (err) {
171
+ resolve('');
172
+ } else {
173
+ resolve(stdout.toString().split('\n')[0]);
174
+ }
175
+ });
176
+ });
177
+ }
178
+ exports.getProcessCommandByPid = getProcessCommandByPid;
179
+ // 判断进程是否死亡
149
180
  function isProcessDied(pid) {
150
- var _a;
151
181
  return __awaiter(this, void 0, void 0, function () {
152
- var name;
153
- return __generator(this, function (_b) {
154
- switch (_b.label) {
182
+ var used;
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
155
185
  case 0:
156
- return [4 /*yield*/, getProcessName(pid)];
186
+ return [4 /*yield*/, getProcessCpuUseByPid(pid)];
157
187
  case 1:
158
- name = _b.sent();
159
- return [2 /*return*/, ((_a = name.split(':')[2]) === null || _a === void 0 ? void 0 : _a.trim()) === 'No such file or directory'];
188
+ used = _a.sent();
189
+ return [2 /*return*/, used < 0];
160
190
  }
161
191
  });
162
192
  });
163
193
  }
164
194
  exports.isProcessDied = isProcessDied;
195
+ // 获取子进程
196
+ function getProcessByPpid(pid) {
197
+ return new Promise(function (resolve) {
198
+ (0, child_process_1.exec)("ps -o pid --no-headers --ppid ".concat(pid), function (err, stdout) {
199
+ if (err) {
200
+ resolve([]);
201
+ } else {
202
+ resolve(stdout.split('\n').filter(function (item) {
203
+ return !!item;
204
+ }).map(function (item) {
205
+ return parseFloat(item.trim());
206
+ }));
207
+ }
208
+ });
209
+ });
210
+ }
211
+ exports.getProcessByPpid = getProcessByPpid;
212
+ // 获取进程树
213
+ var getProcessTree = function getProcessTree(pid, tree) {
214
+ return __awaiter(void 0, void 0, void 0, function () {
215
+ var pids, pids_1, pids_1_1, id, item, e_1_1;
216
+ var e_1, _a;
217
+ return __generator(this, function (_b) {
218
+ switch (_b.label) {
219
+ case 0:
220
+ if (!tree) {
221
+ tree = {
222
+ pid: pid,
223
+ children: []
224
+ };
225
+ }
226
+ return [4 /*yield*/, getProcessByPpid(pid)];
227
+ case 1:
228
+ pids = _b.sent();
229
+ _b.label = 2;
230
+ case 2:
231
+ _b.trys.push([2, 7, 8, 9]);
232
+ pids_1 = __values(pids), pids_1_1 = pids_1.next();
233
+ _b.label = 3;
234
+ case 3:
235
+ if (!!pids_1_1.done) return [3 /*break*/, 6];
236
+ id = pids_1_1.value;
237
+ item = {
238
+ pid: id,
239
+ children: []
240
+ };
241
+ return [4 /*yield*/, (0, exports.getProcessTree)(id, item)];
242
+ case 4:
243
+ _b.sent();
244
+ tree.children.push(item);
245
+ _b.label = 5;
246
+ case 5:
247
+ pids_1_1 = pids_1.next();
248
+ return [3 /*break*/, 3];
249
+ case 6:
250
+ return [3 /*break*/, 9];
251
+ case 7:
252
+ e_1_1 = _b.sent();
253
+ e_1 = {
254
+ error: e_1_1
255
+ };
256
+ return [3 /*break*/, 9];
257
+ case 8:
258
+ try {
259
+ if (pids_1_1 && !pids_1_1.done && (_a = pids_1["return"])) _a.call(pids_1);
260
+ } finally {
261
+ if (e_1) throw e_1.error;
262
+ }
263
+ return [7 /*endfinally*/];
264
+ case 9:
265
+ return [2 /*return*/, tree];
266
+ }
267
+ });
268
+ });
269
+ };
270
+ exports.getProcessTree = getProcessTree;
271
+ // 杀死进程
165
272
  function SIGKILL(pid, type) {
166
273
  if (type === void 0) {
167
274
  type = 2;
@@ -1,10 +1,28 @@
1
1
  /// <reference types="node" />
2
- interface CreateClientProps {
2
+ export interface CreateClientProps {
3
3
  url: string;
4
4
  options?: any;
5
5
  ServiceImp: any;
6
6
  Grpc: any;
7
7
  cert?: Buffer;
8
8
  }
9
+ declare class GrpcClient {
10
+ private readonly url;
11
+ private readonly options;
12
+ private readonly Grpc;
13
+ private readonly credentials;
14
+ private client;
15
+ private _timeout;
16
+ connections: number;
17
+ constructor({ url, options, Grpc, cert }: any);
18
+ request(service: any, method: any, data: any): Promise<any>;
19
+ _request({ service, method, data }: {
20
+ service: any;
21
+ method: any;
22
+ data: any;
23
+ }): Promise<unknown>;
24
+ close(): void;
25
+ }
26
+ export declare const GrpcList: GrpcClient[];
9
27
  export declare function createRpcClient<T>({ url, options, ServiceImp, Grpc, cert }: CreateClientProps): T;
10
28
  export {};
package/lib/grpc/index.js CHANGED
@@ -10,10 +10,128 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) {
15
+ return value instanceof P ? value : new P(function (resolve) {
16
+ resolve(value);
17
+ });
18
+ }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ }
27
+ function rejected(value) {
28
+ try {
29
+ step(generator["throw"](value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ }
34
+ function step(result) {
35
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
36
+ }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
38
+ });
39
+ };
40
+ var __generator = this && this.__generator || function (thisArg, body) {
41
+ var _ = {
42
+ label: 0,
43
+ sent: function sent() {
44
+ if (t[0] & 1) throw t[1];
45
+ return t[1];
46
+ },
47
+ trys: [],
48
+ ops: []
49
+ },
50
+ f,
51
+ y,
52
+ t,
53
+ g;
54
+ return g = {
55
+ next: verb(0),
56
+ "throw": verb(1),
57
+ "return": verb(2)
58
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
59
+ return this;
60
+ }), g;
61
+ function verb(n) {
62
+ return function (v) {
63
+ return step([n, v]);
64
+ };
65
+ }
66
+ function step(op) {
67
+ if (f) throw new TypeError("Generator is already executing.");
68
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
69
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
+ if (y = 0, t) op = [op[0] & 2, t.value];
71
+ switch (op[0]) {
72
+ case 0:
73
+ case 1:
74
+ t = op;
75
+ break;
76
+ case 4:
77
+ _.label++;
78
+ return {
79
+ value: op[1],
80
+ done: false
81
+ };
82
+ case 5:
83
+ _.label++;
84
+ y = op[1];
85
+ op = [0];
86
+ continue;
87
+ case 7:
88
+ op = _.ops.pop();
89
+ _.trys.pop();
90
+ continue;
91
+ default:
92
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
93
+ _ = 0;
94
+ continue;
95
+ }
96
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
97
+ _.label = op[1];
98
+ break;
99
+ }
100
+ if (op[0] === 6 && _.label < t[1]) {
101
+ _.label = t[1];
102
+ t = op;
103
+ break;
104
+ }
105
+ if (t && _.label < t[2]) {
106
+ _.label = t[2];
107
+ _.ops.push(op);
108
+ break;
109
+ }
110
+ if (t[2]) _.ops.pop();
111
+ _.trys.pop();
112
+ continue;
113
+ }
114
+ op = body.call(thisArg, _);
115
+ } catch (e) {
116
+ op = [6, e];
117
+ y = 0;
118
+ } finally {
119
+ f = t = 0;
120
+ }
121
+ if (op[0] & 5) throw op[1];
122
+ return {
123
+ value: op[0] ? op[1] : void 0,
124
+ done: true
125
+ };
126
+ }
127
+ };
13
128
  Object.defineProperty(exports, "__esModule", {
14
129
  value: true
15
130
  });
16
- exports.createRpcClient = void 0;
131
+ exports.createRpcClient = exports.GrpcList = void 0;
132
+ function passThrough(argument) {
133
+ return argument;
134
+ }
17
135
  var GrpcClient = /** @class */function () {
18
136
  function GrpcClient(_a) {
19
137
  var url = _a.url,
@@ -22,6 +140,7 @@ var GrpcClient = /** @class */function () {
22
140
  Grpc = _a.Grpc,
23
141
  cert = _a.cert;
24
142
  var _c;
143
+ this.connections = 0;
25
144
  var opt = __assign({
26
145
  'grpc.max_send_message_length': -1,
27
146
  'grpc.max_receive_message_length': -1
@@ -31,37 +150,95 @@ var GrpcClient = /** @class */function () {
31
150
  this.Grpc = Grpc;
32
151
  this.credentials = credentials;
33
152
  this.options = opt;
34
- this.options.timeout = (_c = this.options.timeout) !== null && _c !== void 0 ? _c : 5000;
153
+ this.options.timeout = (_c = this.options.timeout) !== null && _c !== void 0 ? _c : 60000;
35
154
  }
36
- GrpcClient.prototype.passThrough = function (argument) {
37
- return argument;
38
- };
39
- GrpcClient.prototype.reset = function () {
40
- if (!this.client) {
41
- return;
42
- }
43
- this.client.close();
44
- this.client = null;
45
- };
46
155
  GrpcClient.prototype.request = function (service, method, data) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var error, result, err_1;
158
+ var _this = this;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ this.connections += 1;
163
+ if (!this.client) {
164
+ this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
165
+ }
166
+ _a.label = 1;
167
+ case 1:
168
+ _a.trys.push([1, 3,, 4]);
169
+ return [4 /*yield*/, this._request({
170
+ service: service,
171
+ method: method,
172
+ data: data
173
+ })];
174
+ case 2:
175
+ result = _a.sent();
176
+ return [3 /*break*/, 4];
177
+ case 3:
178
+ err_1 = _a.sent();
179
+ error = err_1;
180
+ return [3 /*break*/, 4];
181
+ case 4:
182
+ this.connections -= 1;
183
+ if (this.connections < 0) {
184
+ this.connections = 0;
185
+ }
186
+ if (this.connections < 1) {
187
+ if (this._timeout) {
188
+ clearTimeout(this._timeout);
189
+ this._timeout = null;
190
+ }
191
+ this._timeout = setTimeout(function () {
192
+ return _this.close();
193
+ }, 60000);
194
+ }
195
+ if (error) {
196
+ this.close();
197
+ throw new Error('grpc connection error.');
198
+ }
199
+ return [2 /*return*/, result];
200
+ }
201
+ });
202
+ });
203
+ };
204
+ GrpcClient.prototype._request = function (_a) {
47
205
  var _this = this;
48
- var path = "/".concat(service, "/").concat(method);
49
- if (!this.client) {
50
- this.client = new this.Grpc.Client(this.url, this.credentials, this.options);
51
- }
206
+ var service = _a.service,
207
+ method = _a.method,
208
+ data = _a.data;
52
209
  return new Promise(function (resolve, reject) {
53
- _this.client.makeUnaryRequest(path, _this.passThrough, _this.passThrough, data, function (err, res) {
210
+ var _ended = false;
211
+ var _timeout = setTimeout(function () {
212
+ _ended = true;
213
+ _this.close();
214
+ console.log('rpc request timeout');
215
+ reject(new Error('timeout'));
216
+ }, _this.options.timeout);
217
+ var _onResponse = function onResponse(err, res) {
218
+ if (_ended) {
219
+ return;
220
+ } else {
221
+ clearTimeout(_timeout);
222
+ }
54
223
  if (err) {
55
- _this.reset();
56
224
  reject(err);
57
225
  } else {
58
226
  resolve(res);
59
227
  }
60
- });
228
+ _onResponse = null;
229
+ };
230
+ _this.client.makeUnaryRequest("/".concat(service, "/").concat(method), passThrough, passThrough, data, _onResponse);
61
231
  });
62
232
  };
233
+ GrpcClient.prototype.close = function () {
234
+ var _a;
235
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.close();
236
+ this.client = null;
237
+ delete this.client;
238
+ };
63
239
  return GrpcClient;
64
240
  }();
241
+ exports.GrpcList = [];
65
242
  function createRpcClient(_a) {
66
243
  var url = _a.url,
67
244
  _b = _a.options,
@@ -75,6 +252,7 @@ function createRpcClient(_a) {
75
252
  Grpc: Grpc,
76
253
  cert: cert
77
254
  });
255
+ exports.GrpcList.push(client);
78
256
  return new ServiceImp({
79
257
  request: client.request.bind(client)
80
258
  });
package/lib/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export { JsonStorage } from './storage/json';
2
2
  export { FtpClient, FtpClientPool, FtpConnectOptions, FtpFile } from './ftp-client';
3
3
  export { createRpcClient } from './grpc';
4
4
  export { PuboFileSystem } from './file-system';
5
- export { SIGKILL, isProcessDied, getProcessName } from './child-process';
5
+ export { SIGKILL, isProcessDied, getProcessName, getProcessTree, getProcessByPpid, getProcessCpuUseByPid, getProcessCommandByPid, } from './child-process';
6
6
  export { isPortAvailable } from './utils';
7
7
  export { pitch } from './pitch';
8
8
  export { getWifiName, getNetworks } from './utils/network';
9
- export { RosTopic, RosTopicManager } from './ros/topic';
9
+ export { RosTopicManager, RosTopic } from './ros/topic';
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RosTopicManager = exports.RosTopic = exports.getNetworks = exports.getWifiName = exports.pitch = exports.isPortAvailable = exports.getProcessName = exports.isProcessDied = exports.SIGKILL = exports.PuboFileSystem = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
6
+ exports.RosTopic = exports.RosTopicManager = exports.getNetworks = exports.getWifiName = exports.pitch = exports.isPortAvailable = exports.getProcessCommandByPid = exports.getProcessCpuUseByPid = exports.getProcessByPpid = exports.getProcessTree = exports.getProcessName = exports.isProcessDied = exports.SIGKILL = exports.PuboFileSystem = exports.createRpcClient = exports.FtpClientPool = exports.FtpClient = exports.JsonStorage = void 0;
7
7
  var json_1 = require("./storage/json");
8
8
  Object.defineProperty(exports, "JsonStorage", {
9
9
  enumerable: true,
@@ -57,6 +57,30 @@ Object.defineProperty(exports, "getProcessName", {
57
57
  return child_process_1.getProcessName;
58
58
  }
59
59
  });
60
+ Object.defineProperty(exports, "getProcessTree", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return child_process_1.getProcessTree;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "getProcessByPpid", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return child_process_1.getProcessByPpid;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "getProcessCpuUseByPid", {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return child_process_1.getProcessCpuUseByPid;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "getProcessCommandByPid", {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return child_process_1.getProcessCommandByPid;
82
+ }
83
+ });
60
84
  var utils_1 = require("./utils");
61
85
  Object.defineProperty(exports, "isPortAvailable", {
62
86
  enumerable: true,
@@ -85,15 +109,15 @@ Object.defineProperty(exports, "getNetworks", {
85
109
  }
86
110
  });
87
111
  var topic_1 = require("./ros/topic");
88
- Object.defineProperty(exports, "RosTopic", {
112
+ Object.defineProperty(exports, "RosTopicManager", {
89
113
  enumerable: true,
90
114
  get: function get() {
91
- return topic_1.RosTopic;
115
+ return topic_1.RosTopicManager;
92
116
  }
93
117
  });
94
- Object.defineProperty(exports, "RosTopicManager", {
118
+ Object.defineProperty(exports, "RosTopic", {
95
119
  enumerable: true,
96
120
  get: function get() {
97
- return topic_1.RosTopicManager;
121
+ return topic_1.RosTopic;
98
122
  }
99
123
  });
package/lib/ros/topic.js CHANGED
@@ -89,18 +89,13 @@ var RosTopic = /** @class */function () {
89
89
  RosTopic.prototype.publish = function (payload) {
90
90
  var _this = this;
91
91
  var data = YAML.stringify(payload);
92
- return new Promise(function (resolve) {
93
- var _a, _b;
94
- var child = (0, child_process_1.exec)("rostopic pub -1 ".concat(_this.topic, " ").concat(_this.messageType, " \"").concat(data, "\""));
95
- (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.once('data', function (buf) {
96
- console.log(buf.toString());
97
- (child === null || child === void 0 ? void 0 : child.pid) && (0, child_process_2.SIGKILL)(child === null || child === void 0 ? void 0 : child.pid);
98
- resolve('');
99
- });
100
- (_b = child.stderr) === null || _b === void 0 ? void 0 : _b.once('data', function (err) {
101
- console.log(err.toString());
102
- (child === null || child === void 0 ? void 0 : child.pid) && (0, child_process_2.SIGKILL)(child === null || child === void 0 ? void 0 : child.pid);
103
- resolve('');
92
+ return new Promise(function (resolve, reject) {
93
+ (0, child_process_1.exec)("rostopic pub -1 ".concat(_this.topic, " ").concat(_this.messageType, " \"").concat(data, "\""), function (err, stdout) {
94
+ if (err) {
95
+ reject(err);
96
+ } else {
97
+ resolve(stdout);
98
+ }
104
99
  });
105
100
  });
106
101
  };
@@ -1,8 +1,10 @@
1
+ export interface JsonStorageOptions {
2
+ initialState?: any;
3
+ defaultState?: any;
4
+ }
1
5
  export declare class JsonStorage {
2
6
  private readonly instance;
3
- constructor(path: string, options?: {
4
- initialState: any;
5
- });
7
+ constructor(path: string, options: JsonStorageOptions);
6
8
  private getState;
7
9
  private setState;
8
10
  get(key?: string): Promise<any>;
@@ -139,8 +139,9 @@ var fs_1 = require("fs");
139
139
  var pubo_utils_1 = require("pubo-utils");
140
140
  var uuid_1 = require("uuid");
141
141
  var cluster = require('cluster');
142
+ // 主线程的实现
142
143
  var Manager = /** @class */function () {
143
- function Manager(path) {
144
+ function Manager(path, defaultState) {
144
145
  var _this = this;
145
146
  this._state = {};
146
147
  this.queue = new pubo_utils_1.SyncQueue();
@@ -169,6 +170,7 @@ var Manager = /** @class */function () {
169
170
  payload = _a.sent();
170
171
  return [3 /*break*/, 4];
171
172
  case 2:
173
+ if (!(message.type === 'set')) return [3 /*break*/, 4];
172
174
  return [4 /*yield*/, this.setState(message.payload)];
173
175
  case 3:
174
176
  payload = _a.sent();
@@ -220,6 +222,7 @@ var Manager = /** @class */function () {
220
222
  });
221
223
  };
222
224
  Manager.prototype.restore = function () {
225
+ var _a;
223
226
  try {
224
227
  var buf = (0, fs_1.readFileSync)(this.path);
225
228
  this._state = JSON.parse(buf.toString());
@@ -230,7 +233,7 @@ var Manager = /** @class */function () {
230
233
  recursive: true
231
234
  });
232
235
  }
233
- this._state = {};
236
+ this.setState((_a = this.defaultState) !== null && _a !== void 0 ? _a : {});
234
237
  }
235
238
  };
236
239
  Manager.prototype.getState = function () {
@@ -257,6 +260,7 @@ var Manager = /** @class */function () {
257
260
 
258
261
  return Manager;
259
262
  }();
263
+ // work 线程的实现
260
264
  var Worker = /** @class */function () {
261
265
  function Worker(path) {
262
266
  this.callback = {};
@@ -318,13 +322,8 @@ var Worker = /** @class */function () {
318
322
  }();
319
323
  var JsonStorage = /** @class */function () {
320
324
  function JsonStorage(path, options) {
321
- if (options === void 0) {
322
- options = {
323
- initialState: null
324
- };
325
- }
326
325
  if (cluster.isPrimary) {
327
- this.instance = new Manager(path);
326
+ this.instance = new Manager(path, options.defaultState);
328
327
  } else {
329
328
  this.instance = new Worker(path);
330
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.129",
3
+ "version": "1.0.136",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "pubo-utils": "^1.0.129",
25
25
  "tree-kill": "^1.2.2"
26
26
  },
27
- "gitHead": "49ff87b8c7333f1e5861c4f83fd0f743d498ae1e",
27
+ "gitHead": "44d452591168455d16a1eefcf65b221df5e8e6e8",
28
28
  "devDependencies": {
29
29
  "@babel/cli": "^7.10.1",
30
30
  "@babel/core": "^7.10.2",