mirror of
https://github.com/minescope/mineping.git
synced 2025-06-18 08:36:14 +03:00
fix: only perform cleanup and fire the callback on the first error
This commit is contained in:
parent
27011d4091
commit
ef2bebe755
@ -113,10 +113,9 @@ const ping = (host, port = 19132, cb, timeout = 5000) => {
|
||||
* @param {Error} err The error that occurred.
|
||||
*/
|
||||
const handleError = (err) => {
|
||||
closeSocket();
|
||||
|
||||
if (!didFireError) {
|
||||
didFireError = true;
|
||||
closeSocket();
|
||||
cb(null, err);
|
||||
}
|
||||
};
|
||||
|
19
lib/java.js
19
lib/java.js
@ -17,7 +17,14 @@ import varint from "./varint.js";
|
||||
* @param {number} [timeout=5000] The timeout duration in milliseconds.
|
||||
* @param {number} [protocolVersion=-1] The protocol version of the Java client.
|
||||
*/
|
||||
function ping(host, virtualHost, port = 25565, cb, timeout = 5000, protocolVersion = -1) {
|
||||
function ping(
|
||||
host,
|
||||
virtualHost,
|
||||
port = 25565,
|
||||
cb,
|
||||
timeout = 5000,
|
||||
protocolVersion = -1
|
||||
) {
|
||||
const socket = net.createConnection({ host, port });
|
||||
|
||||
// Set manual timeout interval.
|
||||
@ -41,10 +48,9 @@ function ping(host, virtualHost, port = 25565, cb, timeout = 5000, protocolVersi
|
||||
* @param {Error} err The error that occurred.
|
||||
*/
|
||||
const handleError = (err) => {
|
||||
closeSocket();
|
||||
|
||||
if (!didFireError) {
|
||||
didFireError = true;
|
||||
closeSocket();
|
||||
cb(null, err);
|
||||
}
|
||||
};
|
||||
@ -132,7 +138,12 @@ function ping(host, virtualHost, port = 25565, cb, timeout = 5000, protocolVersi
|
||||
export function pingJava(host, options = {}) {
|
||||
if (!host) throw new Error("Host argument is not provided");
|
||||
|
||||
const { port = 25565, timeout = 5000, protocolVersion = -1, virtualHost = null } = options;
|
||||
const {
|
||||
port = 25565,
|
||||
timeout = 5000,
|
||||
protocolVersion = -1,
|
||||
virtualHost = null,
|
||||
} = options;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
ping(
|
||||
|
Loading…
x
Reference in New Issue
Block a user