asynchronous 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmJmYTIzN2ZlYTA0NGI0Nzc1NDlmMGY5ZWY1OWY2YTVhOWQ2MzMzNw==
5
+ data.tar.gz: !binary |-
6
+ MTNmMWM4ZTk3ZGRlYjcxYjQwZGRlOWY4MzdmN2ZiNTgyNTUxNDcwNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTA4NTVlNzZhOGJiMzk2ZWNjZjE2M2NiMTEwNTJhMGI3OGY0Zjk5NGIyNDYz
10
+ YThiNWQ4MDUzMGU5MjgzOWVlZTUxZGM0M2M5ZWI3MzM0ODg0YzU5Mjc3N2Nl
11
+ Y2Q4ZDc0ZTFmZDE4NDdmNGJlYzdmMGE5YTE1ZTAxNGYxNzI1OWI=
12
+ data.tar.gz: !binary |-
13
+ MGRmNDU3ZWI0MTZmZDhjNWRmZjQ1NmUzYmU5OTRlNmEyMjQyZTQ3YzVkMzZk
14
+ Y2QzMjZiMTM0ZjhlYmFhMmExMjEyNGIzNzg3OGQwZmIzZGI4MzA3ZjNjYjI2
15
+ YjZjNjE2NzhmMTY3ZmNkZmEzNzRjNDU5NmI4NzBjNTRkMDYxNWM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -0,0 +1,31 @@
1
+ require 'async'
2
+
3
+ async1= async :OS do
4
+
5
+ 1000000*5
6
+
7
+ end
8
+
9
+ async2= async :OS do
10
+
11
+ sleep 10
12
+
13
+ "sup" * 10000
14
+
15
+
16
+ end
17
+
18
+
19
+ async3= async :OS do
20
+
21
+ 1000000*5.0
22
+
23
+ end
24
+
25
+ # please do remember that parsing an object into
26
+ # Marshal String can take up time if you have big Strings like
27
+ # "sup" * 100000000
28
+
29
+ puts async1.value,
30
+ async2.value[0..5],
31
+ async3.value
data/lib/async.rb ADDED
@@ -0,0 +1,4 @@
1
+ #encoding: UTF-8
2
+ module Asynchronous
3
+ require 'asynchronous'
4
+ end
@@ -12,8 +12,7 @@
12
12
  #
13
13
  module Kernel
14
14
  def async(type= :Concurrency ,&block)
15
- type= type.to_s
16
- case type.downcase[0]
15
+ case type.to_s.downcase[0]
17
16
  # Concurrency / VM / Green
18
17
  when "c","v","g"
19
18
  begin
@@ -25,7 +24,9 @@ module Kernel
25
24
  Asynchronous::Parallelism.new(block)
26
25
  end
27
26
  else
28
- nil
27
+ begin
28
+ Asynchronous::Concurrency.new(block)
29
+ end
29
30
 
30
31
  end
31
32
  end
@@ -17,6 +17,7 @@ module Asynchronous
17
17
  @@motherpid ||= $$
18
18
  @@agent ||= nil
19
19
  @@zombie ||= true
20
+ #::Kernel.require 'yaml'
20
21
 
21
22
  end
22
23
 
@@ -43,7 +44,7 @@ module Asynchronous
43
44
  ::Kernel.loop do
44
45
  begin
45
46
  ::Kernel.sleep 1
46
- if mother? == false
47
+ if alive?(@@motherpid) == false
47
48
  ::Kernel.exit!
48
49
  end
49
50
  end
@@ -53,9 +54,16 @@ module Asynchronous
53
54
 
54
55
  # return the value
55
56
  begin
57
+
58
+ return_value= callable.call
59
+
56
60
  @rd.close
57
- @wr.write ::Marshal.dump(callable.call)
61
+ @wr.write ::Marshal.dump(return_value)
62
+ #@wr.write return_value.to_yaml
63
+
58
64
  @wr.close
65
+
66
+ ::Process.exit!
59
67
  end
60
68
 
61
69
  end
@@ -68,80 +76,9 @@ module Asynchronous
68
76
  # connection for in case of mother die
69
77
  begin
70
78
 
71
- #def tmpdir
72
- #
73
- # ::Kernel.require "tmpdir"
74
- # @@tmpdir= ::File.join(::Dir.tmpdir,('asynchronous'))
75
- # unless ::File.directory?(@@tmpdir)
76
- # ::Dir.mkdir(@@tmpdir)
77
- # end
78
- #
79
- # %w[ signal ].each do |one_str|
80
- # unless ::File.directory?(::File.join(@@tmpdir,one_str))
81
- # ::Dir.mkdir(::File.join(@@tmpdir,one_str))
82
- # end
83
- # end
84
- #
85
- # # pidnamed tmp file for tracking
86
- # unless ::File.exist?(::File.join(@@tmpdir,'signal',@@motherpid.to_s))
87
- # ::File.new(::File.join(@@tmpdir,'signal',@@motherpid.to_s),"w").write('')
88
- # end
89
- #
90
- #end
91
- #
92
- #def tmp_write_agent
93
- # if @@agent != true
94
- # ::Thread.new do
95
- # ::Kernel.loop do
96
- # ::File.open(::File.join(@@tmpdir,"signal",@@motherpid.to_s),"w") do |file|
97
- # file.write( ::Time.now.to_i.to_s )
98
- # end
99
- # sleep 3
100
- # end
101
- # end
102
- # @@agent ||= true
103
- # end
104
- #end
105
- #
106
- #def tmp_read
107
- #
108
- # counter= 0
109
- # begin
110
- #
111
- # ::Kernel.loop do
112
- # return_string= ::File.open(
113
- # ::File.join(@@tmpdir,"signal",@@motherpid.to_s),
114
- # ::File::RDONLY
115
- # ).read
116
- #
117
- # if !return_string.nil? && return_string != ""
118
- # return return_string
119
- # else
120
- # if counter > 5
121
- # return nil
122
- # else
123
- # counter += 1
124
- # ::Kernel.sleep(1)
125
- # end
126
- # end
127
- #
128
- # end
129
- #
130
- # rescue ::IOError
131
- # if counter > 5
132
- # return nil
133
- # else
134
- # counter += 1
135
- # end
136
- # ::Kernel.sleep 1
137
- # retry
138
- # end
139
- #
140
- #end
141
-
142
- def mother?
79
+ def alive?(pid)
143
80
  begin
144
- ::Process.kill(0,@@motherpid)
81
+ ::Process.kill(0,pid)
145
82
  return true
146
83
  rescue ::Errno::ESRCH
147
84
  return false
@@ -157,9 +94,22 @@ module Asynchronous
157
94
 
158
95
  if @value.nil?
159
96
 
97
+
98
+ #while alive?(@pid)
99
+ # ::Kernel.puts alive? @pid
100
+ # ::Kernel.sleep 1
101
+ # #sleep 1
102
+ #end
103
+
160
104
  @wr.close
161
- return_value= ::Marshal.load(return_value)
105
+ return_value= @rd.read
162
106
  @rd.close
107
+
108
+ #::Kernel.puts return_value.inspect
109
+
110
+ return_value= ::Marshal.load(return_value)
111
+ #return_value= ::YAML.load(return_value)
112
+
163
113
  @@pids.delete(@pid)
164
114
  @value= return_value
165
115
 
@@ -182,7 +132,7 @@ module Asynchronous
182
132
  begin
183
133
  ::Process.kill(:TERM, pid)
184
134
  rescue ::Errno::ESRCH, ::Errno::ECHILD
185
- ::STDOUT.puts "`kill': No such process (Errno::ESRCH)"
135
+ #::STDOUT.puts "`kill': No such process (Errno::ESRCH)"
186
136
  end
187
137
  }
188
138
  }
data/test/test.rb CHANGED
@@ -1,3 +0,0 @@
1
- # Require Gemfile gems
2
- require_relative "../lib/asynchronous"
3
-
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronous
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Luzsi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-01-16 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: ! 'DSL for for dead simple to use asynchronous patterns in both VM managed
15
14
  and OS managed way (Concurrency and Parallelism) '
@@ -27,9 +26,11 @@ files:
27
26
  - Rakefile
28
27
  - VERSION
29
28
  - asynchronous.gemspec
29
+ - examples/array_of_value_with_native_threads.rb
30
30
  - examples/async_patterns.rb
31
31
  - examples/no_zombie_test.rb
32
32
  - files.rb
33
+ - lib/async.rb
33
34
  - lib/asynchronous.rb
34
35
  - lib/asynchronous/clean_class.rb
35
36
  - lib/asynchronous/concurrency.rb
@@ -39,27 +40,26 @@ files:
39
40
  homepage: https://github.com/adamluzsi/asynchronous
40
41
  licenses:
41
42
  - MIT
43
+ metadata: {}
42
44
  post_install_message:
43
45
  rdoc_options: []
44
46
  require_paths:
45
47
  - lib
46
48
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
49
  requirements:
49
50
  - - ! '>='
50
51
  - !ruby/object:Gem::Version
51
52
  version: '0'
52
53
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
54
  requirements:
55
55
  - - ! '>='
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 1.8.25
60
+ rubygems_version: 2.2.1
61
61
  signing_key:
62
- specification_version: 3
62
+ specification_version: 4
63
63
  summary: Simple Async Based on standard CRuby
64
64
  test_files:
65
65
  - test/test.rb