summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/forecast.rb
diff options
context:
space:
mode:
authorDmitry Kim <dmitry point kim at gmail point com>2007-09-11 17:37:26 +0000
committerDmitry Kim <dmitry point kim at gmail point com>2007-09-11 17:37:26 +0000
commita6738b25dbe4f8eee9223a60622abac5ac6108e5 (patch)
tree9e0129631b5455c4e9d0f41a4832794f9c595718 /data/rbot/plugins/forecast.rb
parent38db12d7482f62275ecf9e67819ae148b3514f9a (diff)
+ (plugins) :thread option for plugin.map makes an action automatically threaded
* (plugins/*) converted to the new threading model
Diffstat (limited to 'data/rbot/plugins/forecast.rb')
-rw-r--r--data/rbot/plugins/forecast.rb61
1 files changed, 30 insertions, 31 deletions
diff --git a/data/rbot/plugins/forecast.rb b/data/rbot/plugins/forecast.rb
index 80790728..1095886f 100644
--- a/data/rbot/plugins/forecast.rb
+++ b/data/rbot/plugins/forecast.rb
@@ -107,41 +107,40 @@ class ForecastPlugin < Plugin
end
def get_forecast(m,loc)
- Thread.new {
- begin
- @cache_mutex.synchronize do
- if @forecast_cache.has_key?(loc) and
- Time.new - @forecast_cache[loc][:date] < 3600
- forecast = @forecast_cache[loc][:forecast]
- if forecast
- m.reply forecast
- Thread.exit
- end
+ begin
+ @cache_mutex.synchronize do
+ if @forecast_cache.has_key?(loc) and
+ Time.new - @forecast_cache[loc][:date] < 3600
+ forecast = @forecast_cache[loc][:forecast]
+ if forecast
+ m.reply forecast
+ return
end
end
- begin
- l = LatLong.new
- f = Forecast.new(*l.get_lat_long(loc))
- forecast,forecast_date = f.forecast
- rescue => err
- m.reply err
- end
- if forecast
- m.reply forecast
- @cache_mutex.synchronize do
- @forecast_cache[loc] = {
- :forecast => forecast,
- :date => forecast_date
- }
- end
- else
- m.reply "Couldn't find forecast for #{loc}"
+ end
+ begin
+ l = LatLong.new
+ f = Forecast.new(*l.get_lat_long(loc))
+ forecast,forecast_date = f.forecast
+ rescue => err
+ m.reply err
+ end
+ if forecast
+ m.reply forecast
+ @cache_mutex.synchronize do
+ @forecast_cache[loc] = {
+ :forecast => forecast,
+ :date => forecast_date
+ }
end
- rescue => e
- m.reply "ERROR: #{e}"
+ else
+ m.reply "Couldn't find forecast for #{loc}"
end
- }
+ rescue => e
+ m.reply "ERROR: #{e}"
+ end
end
end
plugin = ForecastPlugin.new
-plugin.map 'forecast *location', :defaults => {:location => false}
+plugin.map 'forecast *location',
+ :defaults => {:location => false}, :thread => true