amirka-async-fu 1.2.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/async_fu.rb +0 -6
- data/test/test-1.rb +34 -31
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/async_fu.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'fastthread'
|
2
2
|
class AsyncFu
|
3
|
-
|
4
3
|
def initialize(obj = nil)
|
5
4
|
@class = obj || self
|
6
5
|
at_exit{
|
@@ -10,13 +9,9 @@ class AsyncFu
|
|
10
9
|
}
|
11
10
|
end
|
12
11
|
def method_missing(name, *args, &block)
|
13
|
-
if @class.respond_to?(name)
|
14
12
|
Thread.new{
|
15
13
|
@class.send name, *args, &block
|
16
14
|
}
|
17
|
-
else
|
18
|
-
@class.send name, *args, &block
|
19
|
-
end
|
20
15
|
end
|
21
16
|
def exit
|
22
17
|
@exit = true
|
@@ -24,5 +19,4 @@ class AsyncFu
|
|
24
19
|
def self.method_added(method)
|
25
20
|
private method
|
26
21
|
end
|
27
|
-
|
28
22
|
end
|
data/test/test-1.rb
CHANGED
@@ -1,36 +1,39 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'lib/async_fu.rb'
|
3
|
+
#require 'async_fu'
|
3
4
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class Some < AsyncFu
|
6
|
+
def grep(query, path)
|
7
|
+
begin
|
8
|
+
p 'lets play'
|
9
|
+
list = `grep -rne '#{query}' #{path}`
|
10
|
+
File.new( '/tmp/grep.log', 'w' ).write list
|
11
|
+
ensure
|
12
|
+
p 'errors'
|
13
|
+
end
|
14
|
+
p 'we done'
|
15
|
+
end
|
16
|
+
def tick
|
17
|
+
loop{
|
18
|
+
sleep 1
|
19
|
+
p 'tick'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
def tack
|
23
|
+
loop{
|
24
|
+
sleep 2
|
25
|
+
p 'tack'
|
26
|
+
}
|
27
|
+
end
|
12
28
|
end
|
13
29
|
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
def block(&block)
|
26
|
-
block.call
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
ai = YourClass2.new
|
31
|
-
ai.hello
|
32
|
-
p ai.methods
|
33
|
-
ai.block{
|
34
|
-
p 'hello iam block'
|
35
|
-
}
|
36
|
-
ai.exit
|
30
|
+
test = Some.new
|
31
|
+
#test.exit
|
32
|
+
p '1'
|
33
|
+
test.tick
|
34
|
+
p '2'
|
35
|
+
test.grep( 'thread.rb', '/usr/local/lib/ruby' )
|
36
|
+
p '3'
|
37
|
+
test.tack
|
38
|
+
p '4'
|
39
|
+
p test.methods
|