Module: Adhd::UnusedReactor

Defined in:
lib/adhd/reactor.rb

Overview

This module gets mixed into the EventMachine reactor loop, and sends events to our Adhd::Node which is hanging around waiting for stuff to happen.

Currently it just illustrates the fact that we can fire up an EventMachine and have this reactor get mixed in as glue code to our Node.

A call like:

EM.start_server '192.168.1.104', 10000, Adhd::UnusedReactor, @node

inside the EM.run block will start a server on port 10000 when we need a server to do something for us. We can then change it into maybe a file streaming server or whatever we need.

Instance Method Summary collapse

Instance Method Details

#initialize(node) ⇒ Object



21
22
23
24
# File 'lib/adhd/reactor.rb', line 21

def initialize(node)
  puts "Something connected to our server..."
  @node = node
end

#receive_data(data) ⇒ Object



26
27
28
# File 'lib/adhd/reactor.rb', line 26

def receive_data data
  @node.event_handler("received event: #{data}")
end