Module: EF

Defined in:
lib/event-framework.rb

Overview

Event Framework

Event Framework is a minimalistic library providing publish–subscribe pattern

Installing

gem install event-framework

Example

require 'event-framework'

class Server
  include EF::Object
end

class Client
  include EF::Object
end

server = Server.new
client = Client.new

EF::Thread.new do
  loop do
    sleep 1
    server.trigger('event', 'message')
  end
end

EF::Thread.new do
  client.listen_to(server, 'event') do |server, message|
    puts message
  end
end

EF::Loop.loop

Notices

  • EF::Object should be included after initialize

  • Also you may admix EF::Object methods and needed instance variables by extending: ‘Object.new.extend(EF::Object)`

  • Callbacks will be executed in threads of subscribers (where they were defined)

  • In the example the handler will be called in the main thread,
    but if you define the client in the thread where you bind it to the server’s event,
    then the handler will be called in the same thread

Defined Under Namespace

Modules: Loop, Object Classes: Thread