Class: RMExtensions::LongTask
- Inherits:
-
Object
- Object
- RMExtensions::LongTask
- Defined in:
- lib/motion/util.rb
Overview
LongTask encapsulates beginBackgroundTaskWithExpirationHandler/endBackgroundTask:
RMExtensions::BackgroundTask.new(“my long task”) do |task|
do_something_long
task.end!
end
RMExtensions::BackgroundTask.new(“my long task”) do |task|
do_something_long_async do
# later this long task finishes...
task.end!
end
end
Instance Attribute Summary collapse
-
#bgTask ⇒ Object
Returns the value of attribute bgTask.
-
#desc ⇒ Object
Returns the value of attribute desc.
Instance Method Summary collapse
- #end! ⇒ Object
-
#initialize(desc = nil, &block) ⇒ LongTask
constructor
RMExtensions::BackgroundTask.new(“my long task”) { |task| task.end! }.
Constructor Details
#initialize(desc = nil, &block) ⇒ LongTask
RMExtensions::BackgroundTask.new(“my long task”) { |task| task.end! }
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/motion/util.rb', line 29 def initialize(desc=nil, &block) @desc = desc @bgTask = UIApplication.sharedApplication.beginBackgroundTaskWithExpirationHandler(lambda do if ::RMExtensions.debug? p "ERROR: #{self.inspect} #{@desc} didn't call #end! in time!" end UIApplication.sharedApplication.endBackgroundTask(@bgTask) end.weak!) block.call(self) self end |
Instance Attribute Details
#bgTask ⇒ Object
Returns the value of attribute bgTask.
26 27 28 |
# File 'lib/motion/util.rb', line 26 def bgTask @bgTask end |
#desc ⇒ Object
Returns the value of attribute desc.
26 27 28 |
# File 'lib/motion/util.rb', line 26 def desc @desc end |
Instance Method Details
#end! ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/motion/util.rb', line 41 def end! if ::RMExtensions.debug? p "SUCCESS: #{self.inspect} #{@desc} ended successfully." end if @bgTask != UIBackgroundTaskInvalid UIApplication.sharedApplication.endBackgroundTask(@bgTask) @bgTask = UIBackgroundTaskInvalid end end |