<commit_before>require 'at_fork'

# See Cod::Channel::Base for more documentation. 
#
module Cod
  # This gets raised in #create_reference when the identifier passed in is
  # either invalid (has never existed) or when it cannot be turned into an
  # object instance. (Because it might have been garbage collected or other
  # such reasons)
  #
  class InvalidIdentifier < StandardError; end
  
  def beanstalk(url, name)
    context.beanstalk(url, name)
  end
  module_function :beanstalk
  
  def pipe(name=nil)
    context.pipe(name)
  end
  module_function :pipe
  
  def tcp(destination)
    context.tcp(destination)
  end
  module_function :tcp
  
  def tcpserver(bind_to)
    context.tcpserver(bind_to)
  end
  module_function :tcpserver
  
  def context
    @convenience_context ||= Context.new
  end
  module_function :context
  
  # For testing mainly
  #
  def reset<commit_msg>+ Documentation in Cod module<commit_after>require 'at_fork'

# See Cod::Channel::Base for more documentation. 
#
module Cod
  # This gets raised in #create_reference when the identifier passed in is
  # either invalid (has never existed) or when it cannot be turned into an
  # object instance. (Because it might have been garbage collected or other
  # such reasons)
  #
  class InvalidIdentifier < StandardError; end
  
  # Creates a beanstalkd based channel. Messages are written to a tube and 
  # read from it. This channel is read/write. Multiple readers will obtain
  # messages in a round-robin fashion from the beanstalk server. 
  #
  # Example: 
  #   chan = Cod.beanstalk('localhost:11300', 'my_tube')
  #
  def beanstalk(url, name)
    context.beanstalk(url, name)
  end
  module_function :beanstalk
  
  # Creates a IO.pipe based channel. Messages are written to one end of the 
  # pipe and come out on the other end. This channel can have only one reader, 
  # but of course multiple writers. Also, once you either write or read from 
  # such a channel, it will not be available for the other operation anymore. 
  #
  # A common trick is to #dup the channel before using it to either read or
  # write, so that the copy can still be used for both operations. 
  #
  # Note that Cod.pipe channels are usable from process childs (#fork) as 
  # well. As such, they are ideally suited for process control. 
  #
  # Example: 
  #   chan = Cod.pipe
  # 
  def pipe(name=nil)
    context.pipe(name)
  end
  module_function :pipe
  
  def tcp(destination)
    context.tcp(destination)
  end
  module_function :tcp
  
  def tcpserver(bind_to)
    context.tcpserver(bind_to)
  end
  module_function :tcpserver
  
  def context
    @convenience_context ||= Context.new
  end
  module_function :context
  
  # For testing mainly
  #
  def reset
{'fraction_non_alphanumeric': 0.06566946369937979, 'fraction_numerical': 0.0018241517694272164, 'mean_word_length': 3.3523809523809525, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3888562', 'n_tokens_mistral': 849, 'n_tokens_neox': 814, 'n_words': 322}