event 0.9.3 → 1.0.2

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: 04d628a035bccdf1ca709e053665ad377edddd1a27225c95f34c93d214b660bd
4
- data.tar.gz: 2ff2f56bb7e418d6cb0a999524c0aba6fb68db0b91d4751ab6d1a4013ad1aea3
3
+ metadata.gz: 5b493fa7c81f54b3d0d1c8c5db3c3344751da4bc1cba791c955ea9abc493ea2e
4
+ data.tar.gz: 5737fdc584f7e30a8f4289abe2f05a122b308a18c2162e3c7905a73d0589a34c
5
5
  SHA512:
6
- metadata.gz: '08cc9858ac07c66cf211e1fc8763e06a64856440771793d214ceafff6672fbc4ad20869cc900b2d3c234bacddc772c0bee402bdad581bbf651cee34a2c320e6e'
7
- data.tar.gz: bacb375644648693379276cc9b35136ef4498d69d2a9da99e6e146590ed3a50e7bfafa00cb3ebd298e5eb15ac3feb14d5f6042deacf7f4e5612c6a347bc6bd1f
6
+ metadata.gz: 913ab83cf4b8b2bcbb09f56d148f1cd228c8c6a0f060912de8a06afe9d3e56967c9499cc414f723e3a71a607020c3b110f0cc3b911974dcbfe903b29846acdf0
7
+ data.tar.gz: 819f93e1eefef80f90ddc27ac0fc7d4d2e7a88e1e88d88d7d2ef81a43452ff964033a66413ed0a2ec40d868c4371a4c61eb574a5173c47bba33ccf7a90fac269
@@ -26,14 +26,17 @@ static ID id_transfer, id_alive_p;
26
26
  VALUE Event_Selector_fiber_transfer(VALUE fiber, int argc, VALUE *argv) {
27
27
  // TODO Consider introducing something like `rb_fiber_scheduler_transfer(...)`.
28
28
  #ifdef HAVE__RB_FIBER_TRANSFER
29
- if (RTEST(rb_fiber_alive_p(fiber))) {
30
- return rb_fiber_transfer(fiber, argc, argv);
29
+ if (RTEST(rb_obj_is_fiber(fiber))) {
30
+ if (RTEST(rb_fiber_alive_p(fiber))) {
31
+ return rb_fiber_transfer(fiber, argc, argv);
32
+ }
33
+
34
+ return Qnil;
31
35
  }
32
- #else
36
+ #endif
33
37
  if (RTEST(rb_funcall(fiber, id_alive_p, 0))) {
34
38
  return rb_funcallv(fiber, id_transfer, argc, argv);
35
39
  }
36
- #endif
37
40
 
38
41
  return Qnil;
39
42
  }
data/lib/event.rb CHANGED
@@ -20,14 +20,7 @@
20
20
 
21
21
  require_relative 'event/version'
22
22
  require_relative 'event/selector'
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
23
+ require_relative 'event/interrupt'
31
24
 
32
25
  begin
33
26
  require_relative '../ext/event/event'
@@ -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.attach(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.3"
2
+ VERSION = "1.0.2"
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.3
4
+ version: 1.0.2
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