async-container 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/container/forked.rb +10 -1
- data/lib/async/container/threaded.rb +11 -1
- data/lib/async/container/version.rb +1 -1
- data/spec/async/container/forked_spec.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45319be8ef742bece1def74c0ac58a0bb3450f3bec0c80dc34eca3bf28f284eb
|
4
|
+
data.tar.gz: 400b19815897816a89b529a45c95a036a95feb5eed59cc615d88542933d6d974
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91fe53a2d4276196a4dedeb0b66a09c35acb55c06a2f1c7ab5c2708536b40f79914a78d02f1919ca6125cfe68a6b4c1ec967493452262f736f57c751c63b23eb
|
7
|
+
data.tar.gz: 027e9c42c8baa011019ffb42e82646194fff2d54c3a902323aae2d64646f35a224052c309ce5a118c2b4255052616165422c90b42c56f65b0381a73493bb8a19
|
@@ -26,13 +26,22 @@ module Async
|
|
26
26
|
# Manages a reactor within one or more threads.
|
27
27
|
module Container
|
28
28
|
class Forked
|
29
|
+
class Instance
|
30
|
+
def initialize
|
31
|
+
end
|
32
|
+
|
33
|
+
def name= value
|
34
|
+
Process.setproctitle(value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
def initialize(concurrency: 1, name: nil, &block)
|
30
39
|
@pids = concurrency.times.collect do
|
31
40
|
fork do
|
32
41
|
Process.setproctitle(name) if name
|
33
42
|
|
34
43
|
begin
|
35
|
-
Async::Reactor.run(&block)
|
44
|
+
Async::Reactor.run(Instance.new, &block)
|
36
45
|
rescue Interrupt
|
37
46
|
# Exit cleanly.
|
38
47
|
end
|
@@ -27,6 +27,16 @@ module Async
|
|
27
27
|
module Container
|
28
28
|
# Manages a reactor within one or more threads.
|
29
29
|
class Threaded
|
30
|
+
class Instance
|
31
|
+
def initialize(thread)
|
32
|
+
@thread = thread
|
33
|
+
end
|
34
|
+
|
35
|
+
def name= value
|
36
|
+
@thread.name = value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
30
40
|
def initialize(concurrency: 1, name: nil, &block)
|
31
41
|
@reactors = concurrency.times.collect do
|
32
42
|
Async::Reactor.new
|
@@ -40,7 +50,7 @@ module Async
|
|
40
50
|
thread.name = name if name
|
41
51
|
|
42
52
|
begin
|
43
|
-
reactor.run(&block)
|
53
|
+
reactor.run(Instance.new(thread), &block)
|
44
54
|
rescue Interrupt
|
45
55
|
# Exit cleanly.
|
46
56
|
end
|
@@ -22,7 +22,9 @@ require "async/container/forked"
|
|
22
22
|
|
23
23
|
RSpec.describe Async::Container::Forked do
|
24
24
|
it "can run concurrently" do
|
25
|
-
container = described_class.new(concurrency: 8, name: "Sleepy Jerry") do
|
25
|
+
container = described_class.new(concurrency: 8, name: "Sleepy Jerry") do |task, instance|
|
26
|
+
instance.name = "Hello World"
|
27
|
+
|
26
28
|
sleep 1
|
27
29
|
end
|
28
30
|
|