<commit_before>package moh

import (
	"code.google.com/p/go.net/websocket"
	"log"
	"time"
)

type Subscriber struct {
	ws *websocket.Conn
	h  MessageHandler
}

// NewSubscriber opens a websocket connection to a Publisher and
// returns a pointer to newly created Subscriber.
// After creating a Subscriber you should subscribe to messages with Subscribe function.
func NewSubscriber(addr string, h MessageHandler) (*Subscriber, error) {
	url := "ws://" + addr + "/"
	origin := "http://localhost/" // dont know if this is required
	ws, err := websocket.Dial(url, "", origin)
	if err != nil {
		return nil, err
	}

	sub := &Subscriber{
		ws: ws,
		h:  h,
	}
	go sub.consumer()
	return sub, err
}

// Subscribe registers the Subscriber to receive messages matching with the key.
func (s *Subscriber) Subscribe(key string) error {
	return websocket.Message.Send(s.ws, key)
}

func (s *Subscriber) consumer() {
	for {
		var message []byte
		log.Println("Reading from websocket")
		err := websocket.Message.Receive(s.ws, &message)
		if err != nil {
			log.Println("Cannot read message from websocket")
			time.Sleep(100 * time.Millisecond)
			continue
		}
		log.Println("Received data:", message)
		s.h(message)
	}
}
<commit_msg>use more descriptive name for field: handler<commit_after>package moh

import (
	"code.google.com/p/go.net/websocket"
	"log"
	"time"
)

type Subscriber struct {
	ws      *websocket.Conn
	handler MessageHandler
}

// NewSubscriber opens a websocket connection to a Publisher and
// returns a pointer to newly created Subscriber.
// After creating a Subscriber you should subscribe to messages with Subscribe function.
func NewSubscriber(addr string, handler MessageHandler) (*Subscriber, error) {
	url := "ws://" + addr + "/"
	origin := "http://localhost/" // dont know if this is required
	ws, err := websocket.Dial(url, "", origin)
	if err != nil {
		return nil, err
	}

	sub := &Subscriber{
		ws:      ws,
		handler: handler,
	}
	go sub.consumer()
	return sub, err
}

// Subscribe registers the Subscriber to receive messages matching with the key.
func (s *Subscriber) Subscribe(key string) error {
	return websocket.Message.Send(s.ws, key)
}

func (s *Subscriber) consumer() {
	for {
		var message []byte
		log.Println("Reading from websocket")
		err := websocket.Message.Receive(s.ws, &message)
		if err != nil {
			log.Println("Cannot read message from websocket")
			time.Sleep(100 * time.Millisecond)
			continue
		}
		log.Println("Received data:", message)
		s.handler(message)
	}
}

{'fraction_non_alphanumeric': 0.1220675944333996, 'fraction_numerical': 0.002385685884691849, 'mean_word_length': 3.7561436672967865, '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': '7576964', 'n_tokens_mistral': 868, 'n_tokens_neox': 811, 'n_words': 264}