lightning-request-net
Advanced tools
Comparing version
@@ -11,5 +11,10 @@ const net = require('net'); | ||
keepAlive: true, | ||
timeout: 60 * 1000, | ||
}; | ||
} | ||
get destroyed() { | ||
return this.socket.destroyed; | ||
} | ||
constructor(options = {}) { | ||
@@ -36,2 +41,3 @@ this.options = Object.assign(this.defaultOptions, options); | ||
this.socket = new net.Socket(); | ||
this.socket.setTimeout(this.options.timeout); | ||
this.socket.setKeepAlive(this.options.keepAlive); | ||
@@ -113,2 +119,3 @@ this.socket.connect(this.options.port, this.options.host); | ||
debug('socket event -> timeout'); | ||
this.socket.end(); | ||
}) | ||
@@ -137,5 +144,2 @@ .on('drain', () => { | ||
} | ||
setTimeout(() => { | ||
this.socket.connect(this.options.port, this.options.host); | ||
}, 3000); | ||
}); | ||
@@ -142,0 +146,0 @@ } |
@@ -10,8 +10,3 @@ const Connection = require('./connection'); | ||
this.options = options || {}; | ||
this.options.poolOptions = Object.assign( | ||
{ | ||
min: 100, | ||
}, | ||
this.options.poolOptions || {} | ||
); | ||
this.options.poolOptions = Object.assign({}, this.options.poolOptions || {}); | ||
@@ -18,0 +13,0 @@ const factory = { |
{ | ||
"name": "lightning-request-net", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Lightweight Node.js HTTP client based on net.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
14
pool.js
class Pool { | ||
get defaultOptions() { | ||
return { | ||
min: 100, | ||
initialValue: 10, | ||
}; | ||
@@ -16,4 +16,4 @@ } | ||
init() { | ||
const min = this.options.min; | ||
for (let i = 0; i < min; i++) { | ||
const initialValue = this.options.initialValue; | ||
for (let i = 0; i < initialValue; i++) { | ||
this.resources.push(this.factory.create()); | ||
@@ -27,3 +27,9 @@ } | ||
} | ||
return this.resources.pop(); | ||
const conn = this.resources.pop(); | ||
// 判断该连接是否已销毁,如果已销毁,则重新申请,直到申请到一个未销毁的连接 | ||
if (!conn.destroyed) { | ||
return conn; | ||
} else { | ||
return this.acquire(); | ||
} | ||
} | ||
@@ -30,0 +36,0 @@ |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
27867
6.8%13
8.33%359
17.7%1
Infinity%