motion-asyncx 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/motion-asyncx.rb +56 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed844637f9aaab794dde51bee315bd87b1286f26
4
+ data.tar.gz: 9221d2c734aba0559298a111f1378adc5727bfd4
5
+ SHA512:
6
+ metadata.gz: aecdca8811ca95aeb4274292f9dd914043dd05841360797182c7c581907e9cbd70a68541ebab63e1886c421ac41696ef76af57f90367a9a510ac61fc8f96b2a0
7
+ data.tar.gz: ab1a4854e0166994166996b15285969cac77a634b154cda777eee078b5175191bfaa82e64ef996c35a0b8342839a99fd57ce1b25aad8ef8cc0921f7e863ad741
@@ -0,0 +1,56 @@
1
+ class Async
2
+ attr_accessor :blocks
3
+ def initialize
4
+ @blocks = []
5
+ @on_error = nil
6
+ @on_success = nil
7
+ @current = 0
8
+ end
9
+
10
+ def next_block(previous_result=nil)
11
+ block = @blocks[@current]
12
+ completion = lambda do |result=nil, error=nil|
13
+ kp "completion!"
14
+ if error
15
+ @on_error.call(result, error) if @on_error.is_a?(Proc)
16
+ else
17
+ @current += 1
18
+ kp "2-Total blocks: #{@blocks.count}, curr: #{@current}"
19
+ if @blocks.length > @current
20
+ next_block(result)
21
+ elsif @on_success.is_a?(Proc)
22
+ @on_success.call(result)
23
+ else
24
+ p "Done!"
25
+ end
26
+ end
27
+ end
28
+ kp "Total blocks: #{@blocks.count}, curr: #{@current}"
29
+ block.call(completion, previous_result)
30
+ end
31
+
32
+ def self.waterfall(&block)
33
+ chain = Chain.new
34
+ chain.blocks << block
35
+ chain
36
+ end
37
+
38
+ def and_then(&block)
39
+ @blocks << block
40
+ self
41
+ end
42
+
43
+ def on_success(&block)
44
+ @on_success = block
45
+ self
46
+ end
47
+
48
+ def on_error(&block)
49
+ @on_error = block
50
+ self
51
+ end
52
+
53
+ def start
54
+ next_block()
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-asyncx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyrylo Savytskyi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: mail@savytskyi.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/motion-asyncx.rb
20
+ homepage: http://rubygems.org/gems/async-motion
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Chainable async blocks for iOS
44
+ test_files: []