rm-extensions 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/motion/util.rb +76 -4
- data/lib/rm-extensions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79fc90e02999956244b32c6716f3ef47c6c40dce
|
4
|
+
data.tar.gz: 7afd5219125217fe0fe730b8c9ed629ef3dacc91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4972527b0fcb5f5148c1a134e32cec2d458bb2f3c7db95ef83124f3f2bb3c49560b440735b0e5e568b3bbe017dc83431b6a38fee9fd3d52b543c89fc18bb8c94
|
7
|
+
data.tar.gz: c2a1c7fb7cc86cd69eb1bf9d4c8275234d3c2c1d9462a74cffbf1badd342daf42631c72ca5189368de738523756cd1e9498a46dc798a49220dbf574d8642c6f8
|
data/lib/motion/util.rb
CHANGED
@@ -29,30 +29,102 @@ module RMExtensions
|
|
29
29
|
UIApplication.sharedApplication.backgroundTimeRemaining
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
def self.when_all_complete(&block)
|
33
|
+
rmext_on_main_q do
|
34
|
+
if ::RMExtensions::LongTask.outstanding_tasks.size.zero?
|
35
|
+
rmext_block_on_main_q(block)
|
36
|
+
else
|
37
|
+
rmext_once(::RMExtensions::LongTask, :all_complete) do |opts|
|
38
|
+
block.call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.outstanding_queue
|
45
|
+
Dispatch.once do
|
46
|
+
@outstanding_queue = Dispatch::Queue.new("#{NSBundle.mainBundle.bundleIdentifier}.outstanding.LongTask")
|
47
|
+
end
|
48
|
+
@outstanding_queue
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.outstanding_tasks
|
52
|
+
Dispatch.once do
|
53
|
+
@outstanding_tasks = []
|
54
|
+
end
|
55
|
+
@outstanding_tasks
|
56
|
+
end
|
57
|
+
|
58
|
+
# RMExtensions::BackgroundTask.verbose("my long task") { |task| task.end! }
|
59
|
+
def self.verbose(desc=nil, &block)
|
60
|
+
_creator(desc, true, true, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
# RMExtensions::BackgroundTask.create("my long task") { |task| task.end! }
|
33
64
|
def self.create(desc=nil, &block)
|
34
|
-
|
65
|
+
_creator(desc, false, true, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.internal(desc=nil, &block)
|
69
|
+
_creator(desc, false, false, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self._creator(desc=nil, verbose=false, tracking=true, &block)
|
73
|
+
x = new(desc, verbose, tracking)
|
35
74
|
block.weak!.call(x)
|
36
75
|
x
|
37
76
|
end
|
38
77
|
|
39
|
-
def
|
78
|
+
def self.reset_outstanding_tasks!
|
79
|
+
::RMExtensions::LongTask.outstanding_queue.sync do
|
80
|
+
size = ::RMExtensions::LongTask.outstanding_tasks.size
|
81
|
+
if size > 0
|
82
|
+
p "WARNING: reset_outstanding_tasks! (was: #{size})"
|
83
|
+
::RMExtensions::LongTask.outstanding_tasks.removeAllObjects
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def initialize(desc=nil, verbose=false, tracking=true)
|
89
|
+
@verbose = verbose
|
90
|
+
@tracking = tracking
|
40
91
|
@desc = "#{rmext_object_desc} #{desc}"
|
41
92
|
@bgTask = UIApplication.sharedApplication.beginBackgroundTaskWithExpirationHandler(lambda do
|
42
93
|
p "ERROR: #{@desc} didn't call #end! in time!"
|
43
94
|
__end!
|
44
95
|
end)
|
96
|
+
if ::RMExtensions.debug? || @verbose
|
97
|
+
p "CREATED: #{@desc}"
|
98
|
+
end
|
99
|
+
if @tracking
|
100
|
+
::RMExtensions::LongTask.outstanding_queue.sync do
|
101
|
+
::RMExtensions::LongTask.outstanding_tasks << self
|
102
|
+
end
|
103
|
+
end
|
45
104
|
self
|
46
105
|
end
|
47
106
|
|
48
107
|
def end!
|
49
|
-
if ::RMExtensions.debug?
|
108
|
+
if ::RMExtensions.debug? || @verbose
|
50
109
|
p "SUCCESS: #{@desc} ended successfully."
|
51
110
|
end
|
52
111
|
__end!
|
53
112
|
end
|
54
113
|
|
55
114
|
def __end!
|
115
|
+
if @tracking
|
116
|
+
::RMExtensions::LongTask.outstanding_queue.sync do
|
117
|
+
::RMExtensions::LongTask.outstanding_tasks.delete(self)
|
118
|
+
::RMExtensions::LongTask.internal do |internal_task|
|
119
|
+
rmext_on_main_q do
|
120
|
+
if ::RMExtensions::LongTask.outstanding_tasks.size.zero?
|
121
|
+
::RMExtensions::LongTask.rmext_trigger(:all_complete)
|
122
|
+
end
|
123
|
+
internal_task.end!
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
56
128
|
if @bgTask && @bgTask != UIBackgroundTaskInvalid
|
57
129
|
UIApplication.sharedApplication.endBackgroundTask(@bgTask)
|
58
130
|
@bgTask = UIBackgroundTaskInvalid
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rm-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Noon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extensions and helpers for dealing with various areas of rubymotion
|
14
14
|
email:
|