<commit_before>Thread = (require './thread').Thread
ObjectSocket = (require './object_socket').ObjectSocket
util = (require './util')
logError = util.logError
debug = util.debug

class ForkThread extends Thread
 constructor: (opt) ->
  if opt?
   @parent = opt.parent
   @program = opt.program
   @params = opt.params
   @cwd = opt.cwd

  @spawn = false
  @fork = true if @parent? and @parent
  super()
  @connected = false
  @_connect()

 _connect: ->
  @socket = new ObjectSocket this
  @connected = true
  if not @parent
   @process = process

  @process.on 'message', (m) =>
   @socket.onMessage m

 _send: (data) ->
  @process.send data

 send: (method, data, cb) ->
  if not @connected
   cb "Socket is not connected", {}
   return

  @socket.send \
   {method: method, data: data}, \
   (data) ->
    if cb?
     cb data.err, data.data

exports.ForkThread = ForkThread
<commit_msg>add .coffee extension when run with coffee<commit_after>Thread = (require './thread').Thread
ObjectSocket = (require './object_socket').ObjectSocket
util = (require './util')
logError = util.logError
debug = util.debug

class ForkThread extends Thread
 constructor: (opt) ->
  if opt?
   @parent = opt.parent
   @program = opt.program
   @params = opt.params
   @cwd = opt.cwd

  regex = /\.coffee$/
  if @program? and (regex.test __filename) and not (regex.test @program)
   @program += '.coffee'

  @spawn = false
  @fork = true if @parent? and @parent
  super()
  @connected = false
  @_connect()

 _connect: ->
  @socket = new ObjectSocket this
  @connected = true
  if not @parent
   @process = process

  @process.on 'message', (m) =>
   @socket.onMessage m

 _send: (data) ->
  @process.send data

 send: (method, data, cb) ->
  if not @connected
   cb "Socket is not connected", {}
   return

  @socket.send \
   {method: method, data: data}, \
   (data) ->
    if cb?
     cb data.err, data.data

exports.ForkThread = ForkThread

{'fraction_non_alphanumeric': 0.1391484942886812, 'fraction_numerical': 0.0, 'mean_word_length': 3.0654008438818567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2925819', 'n_tokens_mistral': 652, 'n_tokens_neox': 631, 'n_words': 195}