/** * Deep clone object. Note: don't use on objects containing Functions * @param {Object} obj object to be deep cloned */ const deepClone = (obj) => deserialize(serialize(obj))
/** * @method send * @param {String} id * @param {Array} args */ send(id, args) { this._handle.send(id, v8.serialize(args.map((val) => { return this.normalize(id, val); })).buffer ); }
/** * @method constructor * @param {Function|String} script - the path to a worker script or script function directly. */ constructor(script, options=defaultOptions) { const root = path.join(__dirname, '../'); this._handle = new WebWorkerWrap(root, script, this.onRequest.bind(this)); this._refs = {}; this._requests = []; // messaging objects this._postMessage = null; this._queuedMessages = []; // events this._onstdout = null; this._onstderr = null; this._onmessage = null; // TODO(Yorkie): current not supported this._onerror = null; // init this._terminateTimer = options.timeout ? setTimeout(this.terminate.bind(this), options.timeout) : null; const defines = (options.defines || []).map((val, idx) => { return this.normalize(`defines${idx}`, val); }); this._handle.start(v8.serialize(defines).buffer); }