Skip to content

Commit

Permalink
Typescript: remove @class/@extends/@Property declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfent committed Jul 13, 2017
1 parent ba03b66 commit 6e3e4dd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 24 deletions.
25 changes: 19 additions & 6 deletions sockets-workers.js
Expand Up @@ -39,18 +39,16 @@ const SUBCHANNEL_MESSAGE_REGEX = /\|split\n([^\n]*)\n([^\n]*)\n([^\n]*)\n[^\n]*/
* Manages the worker's state for sockets, channels, and
* subchannels. This is responsible for parsing all outgoing and incoming
* messages.
*
* @class Multiplexer
* @property {number} socketCounter
* @property {Map<string, any>} sockets
* @property {Map<string, Map<string, string>>} channels
* @property {?NodeJS.Timer} cleanupInterval
*/
class Multiplexer {
constructor() {
/** @type {number} */
this.socketCounter = 0;
/** @type {Map<string, any>} */
this.sockets = new Map();
/** @type {Map<string, Map<string, string>>} */
this.channels = new Map();
/** @type {?NodeJS.Timer} */
this.cleanupInterval = setInterval(() => this.sweepClosedSockets(), 10 * 60 * 1000);
}

Expand Down Expand Up @@ -85,6 +83,7 @@ class Multiplexer {

/**
* Sends an IPC message to the parent process.
*
* @param {string} token
* @param {string[]} params
*/
Expand All @@ -96,6 +95,7 @@ class Multiplexer {
/**
* Parses the params in a downstream message sent as a
* command.
*
* @param {string} params
* @param {number} count
* @return {string[]}
Expand Down Expand Up @@ -130,6 +130,7 @@ class Multiplexer {

/**
* Parses downstream messages.
*
* @param {string} data
* @return {boolean}
*/
Expand Down Expand Up @@ -168,6 +169,7 @@ class Multiplexer {

/**
* Safely tries to destroy a socket's connection.
*
* @param {any} socket
*/
tryDestroySocket(socket) {
Expand All @@ -179,6 +181,7 @@ class Multiplexer {

/**
* Eval handler for downstream messages.
*
* @param {string} expr
* @return {boolean}
*/
Expand All @@ -192,6 +195,7 @@ class Multiplexer {

/**
* Sockets.socketConnect message handler.
*
* @param {any} socket
* @return {boolean}
*/
Expand Down Expand Up @@ -240,6 +244,7 @@ class Multiplexer {

/**
* Sockets.socketSend message handler.
*
* @param {string} socketid
* @param {string} message
* @return {boolean}
Expand All @@ -255,6 +260,7 @@ class Multiplexer {
/**
* onmessage event handler for sockets. Passes the message
* upstream.
*
* @param {string} socketid
* @param {string} message
* @return {boolean}
Expand Down Expand Up @@ -282,6 +288,7 @@ class Multiplexer {

/**
* Sockets.channelAdd message handler.
*
* @param {string} channelid
* @param {string} socketid
* @return {boolean}
Expand All @@ -303,6 +310,7 @@ class Multiplexer {

/**
* Sockets.channelRemove message handler.
*
* @param {string} channelid
* @param {string} socketid
* @return {boolean}
Expand All @@ -319,6 +327,7 @@ class Multiplexer {
/**
* Sockets.channelSend and Sockets.channelBroadcast message
* handler.
*
* @param {string} channelid
* @param {string} message
* @return {boolean}
Expand All @@ -343,6 +352,7 @@ class Multiplexer {

/**
* Sockets.subchannelMove message handler.
*
* @param {string} channelid
* @param {string} subchannelid
* @param {string} socketid
Expand All @@ -364,6 +374,7 @@ class Multiplexer {

/**
* Sockets.subchannelBroadcast message handler.
*
* @param {string} channelid
* @param {string} message
* @return {boolean}
Expand Down Expand Up @@ -410,7 +421,9 @@ class Multiplexer {
* is already disconnected.
*/
destroy() {
// @ts-ignore
clearInterval(this.cleanupInterval);
this.cleanupInterval = null;
this.sockets.forEach(socket => this.tryDestroySocket(socket));
this.sockets.clear();
this.channels.clear();
Expand Down

0 comments on commit 6e3e4dd

Please sign in to comment.