io-event 1.6.0 → 1.6.4

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: 601c49b58251e4e77e4cfaf2140e834c038ca811c7980dd034f2160440ef7cb2
4
- data.tar.gz: db9a38fc187e6a79d70b38fbb778670ba34d7263f15857aa155dec529117f68c
3
+ metadata.gz: 7e8079059cd981f3843b5887e4eb8b3059330ee939febdf21b2541011ec4a864
4
+ data.tar.gz: fd6c2d19dcd0a63b93a0f395faec3ac11933072f08a2a14de2546a6a402a2b09
5
5
  SHA512:
6
- metadata.gz: 2fd3ca69bacc5f41c70b5502224c2baf5b66d394ea8205dfd8f4da85d61f1d5d0aae1406e649394fbd9fbb7a4b275a8502b65548341c0e2e61e8d4e3b6147ff0
7
- data.tar.gz: 239deeba624f0d2a5bdffdd6ceb2d6660317b7564da5c466887f6cee1492b30fe1828f7012e65d19c59ecd997ed625d5effb7e24522b51a7e24324363590d7a2
6
+ metadata.gz: 887a130e38d3f4e2c514099aaeb8f34925e62b8ec4329d5c93df66db6d4bf277a5b3c3632db5e751b4974ada1b7f5ed99ed2d9cb5de56e26a0aa51bdca0f2e68
7
+ data.tar.gz: 1daa6130d762d3aa8c3df4771327e955813d7bcb18281cc155026dddbbceee5b4a08b52eac31134408e77768a9d7f4a4392b5d2fe8805bfb9353d4b1375f483e
checksums.yaml.gz.sig CHANGED
Binary file
data/ext/extconf.rb CHANGED
@@ -39,6 +39,8 @@ if have_header('sys/event.h')
39
39
  $srcs << "io/event/selector/kqueue.c"
40
40
  end
41
41
 
42
+ have_header('sys/wait.h')
43
+
42
44
  have_header('sys/eventfd.h')
43
45
  $srcs << "io/event/interrupt.c"
44
46
 
@@ -786,24 +786,21 @@ struct timespec * make_timeout(VALUE duration, struct timespec * storage) {
786
786
  return NULL;
787
787
  }
788
788
 
789
- if (FIXNUM_P(duration)) {
789
+ if (RB_INTEGER_TYPE_P(duration)) {
790
790
  storage->tv_sec = NUM2TIMET(duration);
791
791
  storage->tv_nsec = 0;
792
792
 
793
793
  return storage;
794
794
  }
795
795
 
796
- else if (RB_FLOAT_TYPE_P(duration)) {
797
- double value = RFLOAT_VALUE(duration);
798
- time_t seconds = value;
799
-
800
- storage->tv_sec = seconds;
801
- storage->tv_nsec = (value - seconds) * 1000000000L;
802
-
803
- return storage;
804
- }
796
+ duration = rb_to_float(duration);
797
+ double value = RFLOAT_VALUE(duration);
798
+ time_t seconds = value;
799
+
800
+ storage->tv_sec = seconds;
801
+ storage->tv_nsec = (value - seconds) * 1000000000L;
805
802
 
806
- rb_raise(rb_eRuntimeError, "unable to convert timeout");
803
+ return storage;
807
804
  }
808
805
 
809
806
  static
@@ -799,24 +799,21 @@ struct timespec * make_timeout(VALUE duration, struct timespec * storage) {
799
799
  return NULL;
800
800
  }
801
801
 
802
- if (FIXNUM_P(duration)) {
802
+ if (RB_INTEGER_TYPE_P(duration)) {
803
803
  storage->tv_sec = NUM2TIMET(duration);
804
804
  storage->tv_nsec = 0;
805
805
 
806
806
  return storage;
807
807
  }
808
808
 
809
- else if (RB_FLOAT_TYPE_P(duration)) {
810
- double value = RFLOAT_VALUE(duration);
811
- time_t seconds = value;
812
-
813
- storage->tv_sec = seconds;
814
- storage->tv_nsec = (value - seconds) * 1000000000L;
815
-
816
- return storage;
817
- }
809
+ duration = rb_to_float(duration);
810
+ double value = RFLOAT_VALUE(duration);
811
+ time_t seconds = value;
812
+
813
+ storage->tv_sec = seconds;
814
+ storage->tv_nsec = (value - seconds) * 1000000000L;
818
815
 
819
- rb_raise(rb_eRuntimeError, "unable to convert timeout");
816
+ return storage;
820
817
  }
821
818
 
822
819
  static
@@ -34,8 +34,9 @@
34
34
  #endif
35
35
 
36
36
  #include <time.h>
37
- #ifdef HAVE_RB_PROCESS_STATUS_WAIT
38
- #include <sys/wait.h>
37
+
38
+ #ifdef HAVE_SYS_WAIT_H
39
+ #include <sys/wait.h>
39
40
  #endif
40
41
 
41
42
  enum IO_Event {
@@ -901,24 +901,21 @@ struct __kernel_timespec * make_timeout(VALUE duration, struct __kernel_timespec
901
901
  return NULL;
902
902
  }
903
903
 
904
- if (FIXNUM_P(duration)) {
904
+ if (RB_INTEGER_TYPE_P(duration)) {
905
905
  storage->tv_sec = NUM2TIMET(duration);
906
906
  storage->tv_nsec = 0;
907
907
 
908
908
  return storage;
909
909
  }
910
910
 
911
- else if (RB_FLOAT_TYPE_P(duration)) {
912
- double value = RFLOAT_VALUE(duration);
913
- time_t seconds = value;
914
-
915
- storage->tv_sec = seconds;
916
- storage->tv_nsec = (value - seconds) * 1000000000L;
917
-
918
- return storage;
919
- }
911
+ duration = rb_to_float(duration);
912
+ double value = RFLOAT_VALUE(duration);
913
+ time_t seconds = value;
914
+
915
+ storage->tv_sec = seconds;
916
+ storage->tv_nsec = (value - seconds) * 1000000000L;
920
917
 
921
- rb_raise(rb_eRuntimeError, "unable to convert timeout");
918
+ return storage;
922
919
  }
923
920
 
924
921
  static
@@ -420,8 +420,10 @@ module IO::Event
420
420
  duration = 0 unless @ready.empty?
421
421
  error = nil
422
422
 
423
- if duration && duration > 0.0
424
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
423
+ if duration
424
+ if duration > 0
425
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
426
+ end
425
427
  else
426
428
  @idle_duration = 0.0
427
429
  end
@@ -9,20 +9,20 @@ class IO
9
9
  module Event
10
10
  class Timers
11
11
  class Handle
12
- def initialize(offset, block)
13
- @offset = offset
12
+ def initialize(time, block)
13
+ @time = time
14
14
  @block = block
15
15
  end
16
16
 
17
17
  def < other
18
- @offset < other.offset
18
+ @time < other.time
19
19
  end
20
20
 
21
21
  def > other
22
- @offset > other.offset
22
+ @time > other.time
23
23
  end
24
24
 
25
- attr :offset
25
+ attr :time
26
26
  attr :block
27
27
 
28
28
  def call(...)
@@ -49,15 +49,20 @@ class IO
49
49
  return @heap.size
50
50
  end
51
51
 
52
- def schedule(offset, block)
53
- handle = Handle.new(offset, block)
52
+ # Schedule a block to be called at a specific time in the future.
53
+ # @parameter time [Float] The time at which the block should be called, relative to {#now}.
54
+ def schedule(time, block)
55
+ handle = Handle.new(time, block)
56
+
54
57
  @scheduled << handle
55
58
 
56
59
  return handle
57
60
  end
58
61
 
59
- def after(timeout, &block)
60
- schedule(now + timeout, block)
62
+ # Schedule a block to be called after a specific time offset, relative to the current time as returned by {#now}.
63
+ # @parameter offset [#to_f] The time offset from the current time at which the block should be called.
64
+ def after(offset, &block)
65
+ schedule(self.now + offset.to_f, block)
61
66
  end
62
67
 
63
68
  def wait_interval(now = self.now)
@@ -67,7 +72,7 @@ class IO
67
72
  if handle.cancelled?
68
73
  @heap.pop
69
74
  else
70
- return handle.offset - now
75
+ return handle.time - now
71
76
  end
72
77
  end
73
78
  end
@@ -84,7 +89,7 @@ class IO
84
89
  while handle = @heap.peek
85
90
  if handle.cancelled?
86
91
  @heap.pop
87
- elsif handle.offset <= now
92
+ elsif handle.time <= now
88
93
  # Remove the earliest timer from the heap:
89
94
  @heap.pop
90
95
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  class IO
7
7
  module Event
8
- VERSION = "1.6.0"
8
+ VERSION = "1.6.4"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -6,7 +6,7 @@ Provides low level cross-platform primitives for constructing event loops, with
6
6
 
7
7
  ## Motivation
8
8
 
9
- The initial proof-of-concept [Async](https://github.com/socketry/async) was built on [NIO4r](https://github.com/socketry/nio4r). It was perfectly acceptable and well tested in production, however being built on `libev` was a little bit limiting. I wanted to directly built my fiber scheduler into the fabric of the event loop, which is what this gem exposes - it is specifically implemented to support building event loops beneath the fiber scheduler interface, providing an efficient C implementation of all the core operations.
9
+ The initial proof-of-concept [Async](https://github.com/socketry/async) was built on [NIO4r](https://github.com/socketry/nio4r). It was perfectly acceptable and well tested in production, however being built on `libev` was a little bit limiting. I wanted to directly build my fiber scheduler into the fabric of the event loop, which is what this gem exposes - it is specifically implemented to support building event loops beneath the fiber scheduler interface, providing an efficient C implementation of all the core operations.
10
10
 
11
11
  ## Usage
12
12
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -44,7 +44,7 @@ cert_chain:
44
44
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
45
45
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
46
  -----END CERTIFICATE-----
47
- date: 2024-06-03 00:00:00.000000000 Z
47
+ date: 2024-06-13 00:00:00.000000000 Z
48
48
  dependencies: []
49
49
  description:
50
50
  email:
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 3.5.3
104
+ rubygems_version: 3.5.9
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: An event loop.
metadata.gz.sig CHANGED
Binary file