plux 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c413ca368b438a31cc35c74e711937a80ccabad0c55520c73fdc41dd02f4db0
4
- data.tar.gz: 20093ac7f6e387e77142896c28888dffcc947af9e9cc827117b0c015ad0d2b2d
3
+ metadata.gz: fe3a01341377759b20ec857779769a121787a2caa79d1f06c33871e779a4a2db
4
+ data.tar.gz: bdd9a7988dd40776d31b62989b59191b3474436f6a0a847869eb1b568de59303
5
5
  SHA512:
6
- metadata.gz: 1684f9c33a9fab2dc02e2b957448e99d310c0ecf6e71f9e49a605d303b54bd12980654ca5f5c1e9566edf49b09fc5dcb7ead06b1ed5547e94f9fe9572b0308c1
7
- data.tar.gz: 61ace71f940f837f41454a10262849cb090144c8402f29e79176fdd22917df41d8f87a6337aec8dcfe4fc876019363d7ad6078239271e20a5214e0c46e0f352d
6
+ metadata.gz: 1dda3d9c1d45d6acd3af4f8cdba9e3ba954b5d3c8ac0c35cada18ffcf89c08bfe7aabdf31ecb46de30c304a57a78c8762d1b66694244f0b7252974c12337fac5
7
+ data.tar.gz: 142cff4debc8825f8911d2c542d2f03e13a04d49d9a81a8cf414f313073d5be9eb67b608d58c8d03be0ec0a069d4db2c95b1c957769860bb7a841edb6abe05a6
data/README.md CHANGED
@@ -26,12 +26,12 @@ Or install it yourself as:
26
26
  server = Plux.worker(:abc, thread: 2) do
27
27
 
28
28
  # prepare thread-safe resources like mq/db, to handle requests
29
- def initialize
29
+ def prepare
30
30
  # @db = ...
31
31
  end
32
32
 
33
33
  # threads call this method to deal with clients' message
34
- def work(msg)
34
+ def process(msg)
35
35
  # @db << parse(msg)
36
36
  end
37
37
  end
@@ -34,7 +34,8 @@ module Plux
34
34
  end
35
35
 
36
36
  def worker(name, thread: 1, &block)
37
- Server.new(name, thread: thread).boot(block)
37
+ worker = Class.new(&block).new
38
+ Server.new(name, thread: thread).boot(worker)
38
39
  end
39
40
  end
40
41
 
@@ -2,20 +2,7 @@ module Plux
2
2
  class Engine
3
3
 
4
4
  def initialize(name, thread: 1)
5
- engine = self
6
-
7
- @server = ::Plux.worker(name, thread: thread) do
8
- instance_variable_set(:@engine, engine)
9
-
10
- def initialize
11
- @engine = self.class.instance_variable_get(:@engine)
12
- @engine.prepare
13
- end
14
-
15
- def work(msg)
16
- @engine.process(msg)
17
- end
18
- end
5
+ @server = Server.new(name, thread: thread).boot(self)
19
6
  end
20
7
 
21
8
  def connect
@@ -42,7 +42,7 @@ module Plux
42
42
  def process
43
43
  @count.times.each do
44
44
  Thread.new do
45
- loop{ @worker.work(@msg_q.deq) }
45
+ loop{ @worker.process(@msg_q.deq) }
46
46
  end
47
47
  end
48
48
  end
@@ -14,9 +14,9 @@ module Plux
14
14
  @thread = thread
15
15
  end
16
16
 
17
- def boot(block)
17
+ def boot(worker)
18
18
  Plux.lock_pid_file(name) do |file|
19
- start_server_if_not_pid(file, block)
19
+ start_server_if_not_pid(file, worker)
20
20
  end
21
21
  self
22
22
  end
@@ -31,7 +31,7 @@ module Plux
31
31
 
32
32
  private
33
33
 
34
- def start_server_if_not_pid(file, block)
34
+ def start_server_if_not_pid(file, worker)
35
35
  @pid = file.read.to_i
36
36
  return unless pid == 0
37
37
 
@@ -43,7 +43,7 @@ module Plux
43
43
  child.close
44
44
  UNIXServer.open(Plux.server_file(name)) do |serv|
45
45
  parent.close
46
- worker = Proc === block ? Class.new(&block).new : block
46
+ worker.prepare
47
47
  reactor = Reactor.new(@thread, worker)
48
48
  loop{ reactor.register(serv.accept) }
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module Plux
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-22 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler