<commit_before>var deps = [];
var mod = function() {
  /**
   * @description Methods related to SocketIO.
   */
  var Module = {
    /**
     * @description Invoke this helper on the server once it's ready -- it has
     *   attached its (message) observer. The client will be notified of the server's
     *   readiness, and asked to reply about its own readiness.
     * @param {object} socket
     * @param {function} callback
     * @param {number} [DEFAULT: 500] Milliseconds between requests for client reply.
     */
    syncWithClient: function(socket, callback, timeout) {
      var clientReady = false;

      socket.on('ClientReady', function() {
        clientReady = true;
      });

      var requestClientReply = function() {
        if (clientReady) {
          return; // Break cycle.
        }

        socket.emit('ServerReady');

        // Send the event again soon.
        setTimeout(requestClientReply, timeout || 500);
      };

      // Start the poll.
      requestClientReply();
    }
  };

  return Module;
};

define(deps, mod);
<commit_msg>ADD syncWithServer to shared socket helper<commit_after>define([], function() {
  /**
   * @description Methods related to SocketIO.
   */
  var Module = {
    /**
     * @description Invoke this helper on the server once it's ready -- it has
     *   attached its (message) observer. The client will be notified of the server's
     *   readiness, and asked to reply about its own readiness.
     * @param {object} socket
     * @param {function} callback
     * @param {number} [DEFAULT: 500] Milliseconds between requests for client reply.
     */
    syncWithClient: function(socket, callback, timeout) {
      var clientReady = false;

      socket.on('ClientReady', function() {
        clientReady = true;
      });

      var requestClientReply = function() {
        if (clientReady) {
          return; // Break cycle.
        }

        socket.emit('ServerReady');

        // Send the event again soon.
        setTimeout(requestClientReply, timeout || 500);
      };

      // Start the poll.
      requestClientReply();
    },

    /**
     * @description Invoke this helper on the client once it's ready -- it has
     *   attached its (message) observer. The server will be notified of the client's
     *   readiness.
     * @param {object} socket
     * @param {function} callback
     */
    syncWithServer: function(socket, callback) {
      socket.on('ServerReady', _.once(function() {
        socket.emit('ClientReady');
      }));
    }
  };

  return Module;
});

{'fraction_non_alphanumeric': 0.11336982017200939, 'fraction_numerical': 0.004691164972634871, 'mean_word_length': 2.314766839378238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3071154', 'n_tokens_mistral': 718, 'n_tokens_neox': 685, 'n_words': 231}