ref: refs/heads/backgroud_patches_bnc550934 commit 6af76ab2ac32ac3b56c4e68e3db1468a9679172d Author: Ladislav Slezak <lslezak@novell.com> Date: Wed Dec 16 20:09:42 2009 +0100 BackgroundManager - fixed returning values from critical sections BackgroundStatus - code clean up --- webservice/lib/background_manager.rb | 16 ++++++++++++---- webservice/lib/background_status.rb | 11 +++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/webservice/lib/background_manager.rb b/webservice/lib/background_manager.rb index fead92d..2607e86 100644 --- a/webservice/lib/background_manager.rb +++ b/webservice/lib/background_manager.rb @@ -27,16 +27,20 @@ class BackgroundManager # is the process running? def process_running?(id) + ret = false @mutex.synchronize do - return @running.has_key? id + ret = @running.has_key? id end + ret end # is the process finished? def process_finished?(id) + ret = false @mutex.synchronize do - return @done.has_key? id + ret = @done.has_key? id end + ret end # remove the progress status and remember the real final value @@ -50,17 +54,21 @@ class BackgroundManager # get the current progress # returns a copy, use update_progress() for updating the progress def get_progress(id) + ret = nil @mutex.synchronize do ret = @running[id] - ret.nil? ? nil : ret.dup + ret = ret.dup unless ret.nil? end + ret end # get the final value, the value is removed from the internal structure def get_value(id) + ret = nil @mutex.synchronize do - return @done.delete id + ret = @done.delete id end + ret end # update the progress diff --git a/webservice/lib/background_status.rb b/webservice/lib/background_status.rb index 03ea420..7c666cb 100644 --- a/webservice/lib/background_status.rb +++ b/webservice/lib/background_status.rb @@ -13,9 +13,9 @@ class BackgroundStatus @callback = block_given? ? block : nil end - def status=(status) - if @status != status - @status = status + def status=(stat) + if @status != stat + @status = stat trigger_callback end end @@ -27,6 +27,7 @@ class BackgroundStatus end end + # returns -1 if there is no subprogress def subprogress=(s) if @subprogress != s @subprogress = s @@ -48,9 +49,7 @@ class BackgroundStatus private def trigger_callback - if @callback - @callback.call - end + @callback.try(:call) end end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org