Class: Cinch::Callback Private
- Inherits:
-
Object
- Object
- Cinch::Callback
- Includes:
- Helpers
- Defined in:
- lib/cinch/callback.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class used for encapsulating handlers to prevent them from overwriting instance variables in Bot
Instance Attribute Summary collapse
-
#bot ⇒ Bot
readonly
private
Instance Method Summary collapse
-
#initialize(bot) ⇒ Callback
constructor
private
A new instance of Callback.
-
#synchronize(name) { ... }
private
Since Cinch uses threads, all handlers can be run simultaneously, even the same handler multiple times.
Methods included from Helpers
#Channel, #Format, #Sanitize, #Target, #Timer, #Unformat, #User, #debug, #error, #exception, #fatal, #incoming, #info, #log, #outgoing, #rescue_exception, sanitize, #warn
Constructor Details
#initialize(bot) ⇒ Callback
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Callback.
11 12 13 |
# File 'lib/cinch/callback.rb', line 11 def initialize(bot) @bot = bot end |
Instance Attribute Details
#bot ⇒ Bot (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/cinch/callback.rb', line 10 def bot @bot end |
Instance Method Details
#synchronize(name) { ... }
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Since Cinch uses threads, all handlers can be run simultaneously, even the same handler multiple times. This also means, that your code has to be thread-safe. Most of the time, this is not a problem, but if you are accessing stored data, you will most likely have to synchronize access to it. Instead of managing all mutexes yourself, Cinch provides a synchronize method, which takes a name and block.
Synchronize blocks with the same name share the same mutex, which means that only one of them will be executed at a time.
16 17 18 |
# File 'lib/cinch/callback.rb', line 16 def synchronize(name, &block) @bot.synchronize(name, &block) end |