event 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ede0cef441063c9e8675858ccbb0fb10a9e14403e812829531f8a5fedf144499
4
- data.tar.gz: 47519c0f64233d29be411f6148cb1c831734ed36a56f863881d5fa14e2f7245e
3
+ metadata.gz: a4afaae3a40f7c5f5531db11369710205aa5e8f7410edbc8d7311114e733ec91
4
+ data.tar.gz: c8bee5169e94359781b5b3b1eb79f1d535ca992843791709b70794415d144e99
5
5
  SHA512:
6
- metadata.gz: 16a588ae4f5319f430ffd31cf0374defaf099b87db406f27c6af8b667666038725587dfac4d3b328a5496a65335882263b846de1a67934df432beaceae23cff7
7
- data.tar.gz: 61a29c0c4379953b56ac6aef3b002513ac58603f16b2c9656afb61fcfbb91b9954a47bbf3bb04a414977f7ba11205974e229c1d38856fc491b84124cae7814cf
6
+ metadata.gz: cbfe1d0c91aa4ac371f61af680837db84e788dd8ecb8a604f8a76b3ede3a634afa7206f8855f04fa80f2ad93085976bc37b751fd0d48b57a49ffa843b8694be3
7
+ data.tar.gz: 3a37df8c300c32d5c8032d9249a5f9dc303267cf894973fdd177eb6f113a84ad87cf7b65806d06574ba757a3100effd82ab1386fece11219e1e854eba5f11f58
data/lib/event.rb CHANGED
@@ -21,14 +21,6 @@
21
21
  require_relative 'event/version'
22
22
  require_relative 'event/selector'
23
23
 
24
- module Event
25
- # These constants are the same as those defined in IO.
26
-
27
- READABLE = 1
28
- PRIORITY = 2
29
- WRITABLE = 4
30
- end
31
-
32
24
  begin
33
25
  require_relative '../ext/event/event'
34
26
  rescue LoadError
@@ -0,0 +1,55 @@
1
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'selector'
22
+
23
+ module Event
24
+ # A thread safe synchronisation primative.
25
+ class Interrupt
26
+ def self.call(selector, &block)
27
+ self.new(selector, block)
28
+ end
29
+
30
+ def initialize(selector, block)
31
+ @selector = selector
32
+ @input, @output = ::IO.pipe
33
+
34
+ @fiber = Fiber.new do
35
+ while true
36
+ @selector.io_wait(@fiber, @input, READABLE)
37
+ block.call(@input.read_nonblock(1)&.ord)
38
+ end
39
+ end
40
+
41
+ @fiber.transfer
42
+ end
43
+
44
+ # Send a sigle byte interrupt.
45
+ def signal(event = 0)
46
+ @output.write(event.chr)
47
+ @output.flush
48
+ end
49
+
50
+ def close
51
+ @input.close
52
+ @output.close
53
+ end
54
+ end
55
+ end
@@ -21,6 +21,11 @@
21
21
  require_relative 'selector/select'
22
22
 
23
23
  module Event
24
+ # These constants are the same as those defined in IO.
25
+ READABLE = 1
26
+ PRIORITY = 2
27
+ WRITABLE = 4
28
+
24
29
  module Selector
25
30
  def self.default(env = ENV)
26
31
  if name = env['EVENT_SELECTOR']&.to_sym
data/lib/event/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Event
2
- VERSION = "0.9.4"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -87,6 +87,7 @@ files:
87
87
  - ext/event/selector/uring.h
88
88
  - lib/event.rb
89
89
  - lib/event/debug/selector.rb
90
+ - lib/event/interrupt.rb
90
91
  - lib/event/selector.rb
91
92
  - lib/event/selector/select.rb
92
93
  - lib/event/version.rb
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  requirements: []
112
- rubygems_version: 3.3.0.dev
113
+ rubygems_version: 3.2.22
113
114
  signing_key:
114
115
  specification_version: 4
115
116
  summary: An event loop.