motion-async 0.5 → 0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebdc675fdcad19bacb5e6b61b767abb402480031
4
- data.tar.gz: d4880f32b2067e5b3b89a3ba319997cac462de6a
3
+ metadata.gz: ade482b04b4d78ff5cb6f32f6b896394d85953bb
4
+ data.tar.gz: 13c5d56323a038efd25441c4bdc841343904d4e9
5
5
  SHA512:
6
- metadata.gz: 7f95af187c39d1878188ace11f37ab15f64563c09729ff486ca95bd1dd66543f45caf5eb8ec1f804c1c1d27cae55bffc7667bc5c9cf8b6d89bb27bbcd6eee175
7
- data.tar.gz: e442a6f8e3467d4886838d98aadc8b2165a27c5fa7f077a4e149919f9b995110bfad3394b57a9b308123f3953801d46b9d64489a3709b3131d7d431c3cf2b690
6
+ metadata.gz: 026d229e293c450bf559d5722ee1b56d80afd5a14d04bb5d92238810c1e0b33d7e0d4355aafeab6161cca2d4f2ecc5aa22c9fc41f2e446cf74050d6a12b7da3c
7
+ data.tar.gz: af90929ef4b3b8047a0123b94333b9c7870789b58fd17956c51adc53352c3658c3a209d57d0593417ae6192fa7dfa3e57ce8d6c553f60966cb7907b1db111965
data/README.md CHANGED
@@ -189,6 +189,18 @@ task.running?
189
189
  task.finished?
190
190
  ```
191
191
 
192
+ ### Delaying Execution
193
+
194
+ The `after` method works just like `async`, but takes a float as its first parameter to specify the number of seconds to delay before executing the async block:
195
+
196
+ ```ruby
197
+ after(2) do
198
+ p "This won't happen for another 2 seconds"
199
+ end
200
+ ```
201
+
202
+ This works fine for relatively short delays (a few seconds at most), but you'd probably want to use a [Handler](https://developer.android.com/reference/android/os/Handler.html) for anything longer.
203
+
192
204
  ## Development
193
205
 
194
206
  ### Tests
@@ -197,3 +209,6 @@ It's a little tricky to test background threads in a unit test context. I went t
197
209
 
198
210
  So, we've got a few tests in `main_spec.rb` and then a bunch in `main_activity.rb` which are run simply by running the app in this codebase via `rake`. I'm not especially proud of this, but figured it was better than nothing. If anyone can show me a better way, I'd love to see it.
199
211
 
212
+ ## Credits
213
+
214
+ Many, many thanks to [Todd Werth](https://github.com/twerth) and [Jamon Holmgren](https://github.com/jamonholmgren) for helping to define the API. This is a much better gem than it would have been without their input.
@@ -87,6 +87,18 @@
87
87
  # @async_task.cancel
88
88
  # end
89
89
  #
90
+ # Delaying execution
91
+ #
92
+ # The #after method works just like #async, but takes a float as its first parameter to
93
+ # specify the number of seconds to delay before executing the async block.
94
+ #
95
+ # after(2) do
96
+ # p "We did this 2 seconds later"
97
+ # end
98
+ #
99
+ # This works fine for relatively short delays (a few seconds at most), but you'd probably want to use a
100
+ # Handler for anything longer.
101
+ #
90
102
  module MotionAsync
91
103
 
92
104
  def self.async(options={}, &block)
@@ -95,9 +107,17 @@ module MotionAsync
95
107
  end
96
108
  end
97
109
 
110
+ def self.after(delay, options={}, &block)
111
+ MotionAsync.async(options.merge(delay: delay), &block)
112
+ end
113
+
98
114
  def async(options={}, &block)
99
115
  MotionAsync.async(options, &block)
100
116
  end
101
117
 
118
+ def after(delay, options={}, &block)
119
+ MotionAsync.after(delay, options, &block)
120
+ end
121
+
102
122
  end
103
123
 
@@ -1,10 +1,12 @@
1
1
  class MotionAsyncTask < Android::Os::AsyncTask
2
2
  attr_reader :result
3
+ attr_accessor :delay
3
4
 
4
5
  # Java is super picky about constructors, so we'll use a factory method
5
6
  def self.create(options={}, &block)
6
7
  MotionAsyncTask.new.tap do |task|
7
8
  options[:background] = block if block
9
+ task.delay = options.delete(:delay)
8
10
  task.callbacks.merge!(options)
9
11
  end
10
12
  end
@@ -52,6 +54,7 @@ class MotionAsyncTask < Android::Os::AsyncTask
52
54
  end
53
55
 
54
56
  def doInBackground(params)
57
+ sleep self.delay if self.delay
55
58
  @result = call_if_defined :background, self
56
59
  end
57
60
 
@@ -1,4 +1,4 @@
1
1
  module MotionAsync
2
- VERSION = "0.5"
2
+ VERSION = "0.6"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-async
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darin Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bacon