procemon 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,6 +29,10 @@ tells you how to play with proc and method objects source code,
29
29
  combine them, manipulate them, and convert back into live code
30
30
  with the right bindings
31
31
 
32
+ the "simple async processing" will let you use os threads (1.9.n+)
33
+ for multiprocessing so you can give multiple task to do and
34
+ until you ask for the value, the process will be in the background
35
+
32
36
  ## LICENSE
33
37
 
34
38
  (The MIT License)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -0,0 +1,40 @@
1
+ # Require Gemfile gems
2
+ require_relative "../lib/procemon"
3
+
4
+ calculation = async {
5
+
6
+ sleep 10
7
+ 4 * 4
8
+ }
9
+
10
+ puts "hello world"
11
+
12
+ calculation += 1
13
+
14
+ puts calculation
15
+
16
+ #>--------------------------------------------------
17
+
18
+
19
+ test1 = async {
20
+
21
+ sleep 8
22
+ hello= 14
23
+ sup= "the world is yours"
24
+
25
+ sup
26
+
27
+ }
28
+
29
+ test2 = async {
30
+ sleep(4)
31
+ "world"
32
+ }
33
+
34
+ start_time= Time.now
35
+
36
+ asd= test1
37
+ puts asd
38
+
39
+ puts test1.value == test2.value
40
+ puts Time.now-start_time
@@ -0,0 +1,58 @@
1
+ Thread.abort_on_exception= true
2
+ class Async #< BasicObject
3
+
4
+ # remove methods!
5
+ (Async.instance_methods-[
6
+ :undef_method,
7
+ :object_id,
8
+ :__send__,
9
+ :new
10
+ ]).each do |method|
11
+ undef_method method
12
+ end
13
+
14
+ @@max_retry ||= 6
15
+ def initialize(callable)
16
+ retry_times= nil
17
+ begin
18
+ @thread ||= ::Thread.new { callable.call }
19
+ rescue ThreadError
20
+ retry_times ||= 0
21
+ retry_times += 1
22
+ sleep 5
23
+ if retry_times <= @@max_retry
24
+ retry
25
+ else
26
+ @thread ||= callable.call
27
+ end
28
+ end
29
+ end
30
+
31
+ def value
32
+
33
+ #unless @thread.alive?
34
+ #else
35
+ # sleep 1
36
+ #end
37
+
38
+ return @thread.value
39
+
40
+ end
41
+
42
+ def inspect
43
+ if @thread.alive?
44
+ "#<Async running>"
45
+ else
46
+ value.inspect
47
+ end
48
+ end
49
+
50
+ def method_missing(method, *args)
51
+ value.__send__(method, *args)
52
+ end
53
+
54
+ def respond_to_missing?(method, include_private = false)
55
+ value.respond_to?(method, include_private)
56
+ end
57
+
58
+ end
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def async(&block)
3
+ Async.new(block)
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ class User
2
+ class << self
3
+ attr_reader :fields
4
+
5
+ def field (*names)
6
+ names.flatten.each do |name|
7
+ attr_accessor name
8
+ (@fields ||= []) << name
9
+ end
10
+ end
11
+ end
12
+
13
+ field :name
14
+ field :age
15
+ field :address
16
+ end
17
+
18
+ user = User.new
19
+ user.age = 22
20
+ user.address = "1234"
21
+ user.name = "Me"
22
+
23
+ #user.class.fields.each do |field|
24
+ # puts user.send(field)
25
+ #end
26
+
27
+ puts user.name
@@ -1,17 +1,22 @@
1
1
  # Require Gemfile gems
2
- require 'grape'
3
2
  require_relative "../lib/procemon"
4
3
 
5
- Grape::API.inject_singleton_method :inherited, add: "after" do |subclass|
6
4
 
7
- subclass.class_eval do
5
+ test1 = async {
8
6
 
9
- before do
10
- puts "hello world!"
11
- end
7
+ sleep 8
8
+ hello= 14
9
+ sup= "the world is yours"
12
10
 
13
- end
11
+ sup
14
12
 
15
- end
13
+ }
16
14
 
17
- puts "hello".binding?
15
+ test2 = async {
16
+ sleep(4)
17
+ "world"
18
+ }
19
+
20
+ start_time= Time.now
21
+ puts test1.value == test2.value
22
+ puts Time.now-start_time
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-03 00:00:00.000000000 Z
12
+ date: 2014-01-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
15
15
  the best! In short this provides extra tools in Application configs, argumens processing,daemonise,
@@ -29,11 +29,14 @@ files:
29
29
  - VERSION
30
30
  - examples/fun_with_procs_and_methods.rb
31
31
  - examples/how_to_inject_with_extra_process_a_method.rb
32
+ - examples/simple async processing.rb
32
33
  - files.rb
33
34
  - lib/procemon.rb
34
35
  - lib/procemon/extra/str2duck.rb
35
36
  - lib/procemon/function/application.rb
36
37
  - lib/procemon/function/argv.rb
38
+ - lib/procemon/function/async/async.rb
39
+ - lib/procemon/function/async/kernel.rb
37
40
  - lib/procemon/function/binding/binding.rb
38
41
  - lib/procemon/function/binding/bindless.rb
39
42
  - lib/procemon/function/daemon.rb
@@ -74,6 +77,7 @@ files:
74
77
  - scripts/test.txt
75
78
  - test/hello/world/file.rb
76
79
  - test/lab.rb
80
+ - test/prototype/class_field.rb
77
81
  - test/test.rb
78
82
  homepage: https://github.com/adamluzsi/procemon
79
83
  licenses:
@@ -103,5 +107,6 @@ summary: Gotta catch em all!
103
107
  test_files:
104
108
  - test/hello/world/file.rb
105
109
  - test/lab.rb
110
+ - test/prototype/class_field.rb
106
111
  - test/test.rb
107
112
  has_rdoc: