-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathutils.js
More file actions
31 lines (28 loc) · 957 Bytes
/
utils.js
File metadata and controls
31 lines (28 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* WebSocket Utilities
* Shared helper functions used across websocket modules.
*/
/**
* Check if WebSocket connection is ready for sending.
* Replaces the repeated pattern: !ws || !ws.readyState || ws.readyState !== 1
* @param {WebSocket} ws - WebSocket instance
* @returns {boolean} - True if connection is ready
*/
exports.isConnectionReady = (ws) => !!(ws && ws.readyState === 1);
/**
* Propagate an error through hooks and logger.
* @param {Object} hooks - Hooks module
* @param {Object} logger - Logger module
* @param {string} message - Error message
*/
exports.propagateError = (hooks, logger, message) => {
hooks.trigger('error', new Error(message));
logger.debug(message);
};
/**
* Delay execution by specified milliseconds.
* @param {number} ms - Milliseconds to delay
* @param {Function} cb - Callback to execute after delay
* @returns {NodeJS.Timeout} - Timeout ID
*/
exports.delay = (ms, cb) => setTimeout(cb, ms);