GithubHelp home page GithubHelp logo

mikbe / eventable Goto Github PK

View Code? Open in Web Editor NEW
126.0 3.0 4.0 212 KB

Eventable is an easy to use and understand event model; it's the simplest way to add fine-grain events to your classes.

License: MIT License

Shell 0.46% Ruby 99.54%

eventable's Issues

calling fire_event in an event class w/o first registering listeners raises and error.

$ irb
ruby-1.9.2-p180 :001 > require 'eventable'
 => true 
ruby-1.9.2-p180 :002 > 
ruby-1.9.2-p180 :003 >   class EventClass
ruby-1.9.2-p180 :004?>     include Eventable
ruby-1.9.2-p180 :005?>   
ruby-1.9.2-p180 :006 >       # This is all you have to do to add an event (after you include Eventable)
ruby-1.9.2-p180 :007 >       event :stuff_happens
ruby-1.9.2-p180 :008?>   
ruby-1.9.2-p180 :009 >       # don't name your method fire_event, that's taken
ruby-1.9.2-p180 :010 >       def do_event
ruby-1.9.2-p180 :011?>         puts "firing :stuff_happens"
ruby-1.9.2-p180 :012?>         # And this is all you have to do to make the event happen
ruby-1.9.2-p180 :013 >           fire_event(:stuff_happens, rand(1000))
ruby-1.9.2-p180 :014?>       end
ruby-1.9.2-p180 :015?>   
ruby-1.9.2-p180 :016 >     end
 => nil 
ruby-1.9.2-p180 :017 > 
ruby-1.9.2-p180 :018 >   # Create an instance of a class that has an event
ruby-1.9.2-p180 :019 >   evented   = EventClass.new
 => #<EventClass:0x1bad00> 
ruby-1.9.2-p180 :020 > # We'll just arbitrarilly fire the event to see how it works
ruby-1.9.2-p180 :021 >   evented.do_event
firing :stuff_happens
NoMethodError: undefined method `synchronize' for nil:NilClass
    from ~/.rvm/gems/ruby-1.9.2-p180@develop/gems/eventable-0.1.0/lib/eventable/eventable.rb:36:in `fire_event'
    from (irb):13:in `do_event'
    from (irb):21
    from ~/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
ruby-1.9.2-p180 :022 > 

This is because line 36 of eventable.rb tries to synchronize on a mutex that doesn't exist. The mutex is created in the registration of a first event.

Possible fix is to guard the synchronize call with a nil check?

The next thing, I'm not sure about because I'm unfamiliar with underlying language implementation in the VMs. This is me mostly just pondering because of the likelihood of this happening seems very small.

Also, could there exist a possible problem (seems very unlikely, but theoretically possible) when multiple threads attempt to register listeners at the same time on an event class that has had no previous registered listeners. The call:

    @mutex ||= Mutex.new

I don't think the ||= operator is atomic??? Thus it possibly be that thread A sees that @mutex is nil so it will create a new mutex. But before the assignment, that thread is immediately interrupted by thread B who is also registering an event. It goes past this line, creating a new mutex. Then thread A runs again, thus completing the mutex assignment. They both run code in the synchronized block... And proceeds to do unpredictable things in the ||= type assignments in the protected code w.r.t the @callbacks.

Invalid gemspec in [...] invalid date format in specification: "2011-06-06 00:00:00.000000000Z"

$ ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [i386-darwin9.8.0]

$ gem --version
1.8.2

$ gem install eventable
Fetching: eventable-0.1.0.gem (100%)
Invalid gemspec in [/.rvm/gems/ruby-1.9.2-p180@develop/specifications/eventable-0.1.0.gemspec]: invalid date format in specification: "2011-06-06 00:00:00.000000000Z"
ERROR: While executing gem ... (NoMethodError)
undefined method `name' for nil:NilClass
[
]
$

Now this error'd gemspec essentially denies the ruby system from being able to boot.

Removing the time segment from the gemspec seems to fix the problem.

Event callbacks are blocking

Event callbacks are currently blocking so if one callback locks up it breaks all the following callbacks and the evented class itself locks up.

Callbacks should be threaded/fibered to avoid this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.