Skip to content

Commit

Permalink
Fix an issue in the event code (from rhuidean).
Browse files Browse the repository at this point in the history
Allow the same event to be posted more than once to the same queue. If
this is done it can allow things like two "this socket is ready to be
read from" events to be posted and result in two calls to read(), one
of which will wind up blocking. This is bad. However, NOT allowing this
results in worse things, like if a certain event-triggering data comes
in more than once in a single read()/event loop it results it it only
being processed once and will ignore the rest. This is unacceptable.
Since the former can be corrected with good coding, and the latter
cannot, then the former loses (thanks sycobuny).
  • Loading branch information
rakaur committed Sep 19, 2010
1 parent cf5b590 commit b365d31
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/kintara/event.rb
Expand Up @@ -48,18 +48,18 @@ def initialize

##
# Post a new event to the queue to be handled.
# Events can be posted more than once per loop,
# so the callers need to make sure calling the
# same handlers twice for the same run isn't going
# to bork something serious like make an otherwise
# good call become blocking (like read).
# ---
# event:: event name as a Symbol
# args:: list of arguments to pass to handler
# returns:: +self+
#
def post(event, *args)
# Only one post per event per loop, otherwise we end up trying
# to read from a socket that has no data, or stuff like that.
return if m = @queue.find { |q| q.event == event }

@queue << Event.new(event, *args)

self
end

Expand Down

0 comments on commit b365d31

Please sign in to comment.