arturo-client
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _debug = require('debug'); | ||
var _debug2 = _interopRequireDefault(_debug); | ||
var _nssocket = require('nssocket'); | ||
@@ -14,8 +18,12 @@ | ||
let id = 0; | ||
class Client { | ||
constructor(opts) { | ||
this._opts = Object.assign({ | ||
port: 61818 | ||
port: 61681 | ||
}, opts); | ||
this.uuid = `${this.constructor.name}-${process.pid}-${id++}`; | ||
this.debug = (0, _debug2.default)(`arturo:${this.uuid}`); | ||
this._connection = null; | ||
@@ -30,4 +38,7 @@ } | ||
connection.on('close', err => err && reject(err)); | ||
connection.on('timeout', () => client.close()); | ||
connection.data(['connected'], () => resolve()); | ||
connection.on('timeout', () => connection.close()); | ||
connection.data(['connected'], () => { | ||
this.debug('connected'); | ||
resolve(connection); | ||
}); | ||
connection.connect(this._opts.port); | ||
@@ -41,2 +52,3 @@ }); | ||
async _transmit(method, data) { | ||
const self = this; | ||
const workers = Client.toArray(data); | ||
@@ -48,5 +60,6 @@ const connection = await this.connection(); | ||
const successEvent = ['worker', method, 'success']; | ||
client.on(successEvent, function onSuccess(result) { | ||
if (result.id !== worker.id) return; | ||
client.removeListener(successEvent, onSuccess); | ||
connection.data(successEvent, function onSuccess(result) { | ||
if (result.route !== worker.route) return; | ||
self.debug(`create worker ${result.route} success!`); | ||
connection.removeListener(successEvent, onSuccess); | ||
resolve(); | ||
@@ -56,9 +69,11 @@ }); | ||
const errorEvent = ['worker', method, 'error']; | ||
client.on(errorEvent, function onError(result) { | ||
if (result.id !== worker.id) return; | ||
client.removeListener(errorEvent, onError); | ||
connection.data(errorEvent, function onError(result) { | ||
if (result.route !== worker.route) return; | ||
self.debug(`create worker ${result.route} error.`); | ||
connection.removeListener(errorEvent, onError); | ||
reject(); | ||
}); | ||
client.send(['worker', method], worker); | ||
this.debug(`create worker ${worker.route}`); | ||
connection.send(['worker', method], worker); | ||
}).catch(err => console.error(err))); | ||
@@ -65,0 +80,0 @@ |
{ | ||
"name": "arturo-client", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "lib/Client.js", | ||
@@ -5,0 +5,0 @@ "author": "chad.d.elliott@gmail.com", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105407
78