tra 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tra/fork.rb +7 -0
- data/lib/tra/mailbox.rb +16 -0
- data/lib/tra/run.rb +2 -0
- data/lib/tra.rb +41 -0
- data/test.rb +17 -0
- data/tra.gemspec +7 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd1da5cafab185749f54bea2504134b1938be798
|
4
|
+
data.tar.gz: 180cbc81a2ed58a413207cd2a76c805351d3e3e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 476768c1029e5d715004a3339b5c5121409e8e44c45e8f0f65cc85001f4a73bf2db2cd3f2698718187ab611be10b7b2d2d0d92cade11e268d5795cdb3009ee64
|
7
|
+
data.tar.gz: e7d27d0e95e8419d24fbaf6079b543a538859fa96b23be7f0e9aec0884586eb4843d69ec0b64a23f45b23f6dc3151cf6b9e0da6982004dffea46388451094fe5
|
data/lib/tra/fork.rb
ADDED
data/lib/tra/mailbox.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tra
|
2
|
+
module Mailbox
|
3
|
+
def self.receive
|
4
|
+
Dir.mkdir DIRECTORY unless Dir.exist? DIRECTORY
|
5
|
+
file = FILE[Process.pid]
|
6
|
+
|
7
|
+
Thread.new do
|
8
|
+
Socket.unix_server_loop file do |socket|
|
9
|
+
QUEUE << (Marshal.load socket.gets)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
sleep 0.01 until File.exist? file
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/tra/run.rb
ADDED
data/lib/tra.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
require_relative 'tra/mailbox'
|
5
|
+
require_relative 'tra/fork'
|
6
|
+
|
7
|
+
module Tra
|
8
|
+
QUEUE = Queue.new
|
9
|
+
|
10
|
+
DIRECTORY = "/tmp/tractor"
|
11
|
+
FILE = -> pid { "#{DIRECTORY}/#{pid}" }
|
12
|
+
|
13
|
+
class << self
|
14
|
+
ENUMERATOR = Enumerator.new do |y|
|
15
|
+
loop { y << QUEUE.pop }
|
16
|
+
end
|
17
|
+
|
18
|
+
extend Forwardable
|
19
|
+
delegate [:next, :take] => :ENUMERATOR
|
20
|
+
|
21
|
+
def run
|
22
|
+
Mailbox.receive
|
23
|
+
|
24
|
+
patch_Object_shamelessly
|
25
|
+
patch_Integer_shamelessly
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def patch_Object_shamelessly
|
30
|
+
Object.prepend Fork
|
31
|
+
end
|
32
|
+
|
33
|
+
def patch_Integer_shamelessly
|
34
|
+
Integer.class_eval do
|
35
|
+
def put message
|
36
|
+
Socket.unix(FILE[self]).write "#{Marshal.dump message}\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'lib/tra'
|
2
|
+
Tra.run
|
3
|
+
|
4
|
+
child = fork do
|
5
|
+
message = [1,2,3]
|
6
|
+
p Process.ppid
|
7
|
+
5.times { Process.ppid.put message }
|
8
|
+
p Tra.next
|
9
|
+
end
|
10
|
+
|
11
|
+
=begin
|
12
|
+
require 'pry'
|
13
|
+
binding.pry
|
14
|
+
p Tra.next
|
15
|
+
=end
|
16
|
+
Tra.take(5).each { |message| p message }
|
17
|
+
child.put [:my, :message]
|
data/tra.gemspec
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tra.rb
|
20
|
+
- lib/tra/fork.rb
|
21
|
+
- lib/tra/mailbox.rb
|
22
|
+
- lib/tra/run.rb
|
23
|
+
- test.rb
|
24
|
+
- tra.gemspec
|
25
|
+
homepage:
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.5.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Erlang-style messaging for Ruby processes
|
48
|
+
test_files: []
|