motion-asyncx 0.0.1 → 0.0.2
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 +4 -4
- data/lib/motion-asyncx.rb +5 -53
- data/lib/motion-asyncx/async.rb +53 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3ddd6b1f8289426db4be67dbe903f167b11fb78
|
4
|
+
data.tar.gz: f7fb1503b4426abb919dd3e992323223df3c5ee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c636670ae2b9bf302e3262bd7966d5854c0a42effebc282ec0a549a4b3a6e6155eefd1757e9d9cb7c96fdb0f7b4cbeb2c3ede8f123228554b77d5419d0f567
|
7
|
+
data.tar.gz: a6abc7f8a06e693aaf0efe8b1a03266548d1d8dbf85af6c59d60b4e7fd61b05b2500c2f93bde2e9ef44fa5525e17545c35bf7068afda47bc821eb256bc6d469b
|
data/lib/motion-asyncx.rb
CHANGED
@@ -1,56 +1,8 @@
|
|
1
|
-
|
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
|
1
|
+
gem_name = File.basename(__FILE__).gsub(/\.rb$/, "")
|
52
2
|
|
53
|
-
|
54
|
-
|
3
|
+
Motion::Project::App.setup do |app|
|
4
|
+
app.development do
|
5
|
+
gem_files = Dir.glob(File.join(File.dirname(__FILE__), gem_name, "**/*.rb"))
|
6
|
+
app.files = gem_files + app.files
|
55
7
|
end
|
56
8
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Async
|
2
|
+
class Waterfall
|
3
|
+
attr_accessor :blocks
|
4
|
+
def initialize
|
5
|
+
@blocks = []
|
6
|
+
@on_error = nil
|
7
|
+
@on_success = nil
|
8
|
+
@current = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def next_block(previous_result=nil)
|
12
|
+
block = @blocks[@current]
|
13
|
+
completion = lambda do |result=nil, error=nil|
|
14
|
+
if error
|
15
|
+
@on_error.call(result, error) if @on_error.is_a?(Proc)
|
16
|
+
else
|
17
|
+
@current += 1
|
18
|
+
if @blocks.length > @current
|
19
|
+
next_block(result)
|
20
|
+
elsif @on_success.is_a?(Proc)
|
21
|
+
@on_success.call(result)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
block.call(completion, previous_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.do(&block)
|
29
|
+
chain = Waterfall.new
|
30
|
+
chain.blocks << block
|
31
|
+
chain
|
32
|
+
end
|
33
|
+
|
34
|
+
def and_then(&block)
|
35
|
+
@blocks << block
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_success(&block)
|
40
|
+
@on_success = block
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_error(&block)
|
45
|
+
@on_error = block
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def start
|
50
|
+
next_block()
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-asyncx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyrylo Savytskyi
|
@@ -17,6 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/motion-asyncx.rb
|
20
|
+
- lib/motion-asyncx/async.rb
|
20
21
|
homepage: http://rubygems.org/gems/async-motion
|
21
22
|
licenses:
|
22
23
|
- MIT
|