io-event 1.12.1 → 1.13.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +61 -0
- data/context/index.yaml +11 -0
- data/ext/extconf.rb +3 -3
- data/lib/io/event/debug/selector.rb +1 -1
- data/lib/io/event/priority_heap.rb +6 -1
- data/lib/io/event/selector/select.rb +1 -1
- data/lib/io/event/support.rb +1 -1
- data/lib/io/event/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a32ca73de2138ec23628217095bdfd7414f9b898e2af962922e449b297b20821
|
4
|
+
data.tar.gz: 67d4d9f80ec4195efdda39dc71ed5c84772336bcf1701d691115212143fd6912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e19eb71a5f491b3513f2506474e2b184e9b4231e70cd9282b8ebdb38a214133c2d1b4fdf77d1a502c2758b29b1fe2160f55b47e060e6cd24fe36a5ed646405
|
7
|
+
data.tar.gz: 6ad9a898bb51eea78a28160b1d12ba8ffea073842971741c264ffad4f71e96d722289ebd840f5a2f365361926e98819b4e45014860dc4cd1eaa0f96c4fd540a1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Getting Started
|
2
|
+
|
3
|
+
This guide explains how to use `io-event` for non-blocking IO.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your project:
|
8
|
+
|
9
|
+
~~~ bash
|
10
|
+
$ bundle add io-event
|
11
|
+
~~~
|
12
|
+
|
13
|
+
## Core Concepts
|
14
|
+
|
15
|
+
`io-event` has several core concepts:
|
16
|
+
|
17
|
+
- A {ruby IO::Event::Selector} implementation which provides the primitive operations for implementation an event loop.
|
18
|
+
- A {ruby IO::Event::Debug::Selector} which adds extra validations and checks at the expense of performance. You should generally use this during tests.
|
19
|
+
|
20
|
+
## Basic Event Loop
|
21
|
+
|
22
|
+
This example shows how to perform a blocking operation
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'fiber'
|
26
|
+
require 'io/event'
|
27
|
+
|
28
|
+
selector = IO::Event::Selector.new(Fiber.current)
|
29
|
+
input, output = IO.pipe
|
30
|
+
|
31
|
+
writer = Fiber.new do
|
32
|
+
output.write("Hello World")
|
33
|
+
output.close
|
34
|
+
end
|
35
|
+
|
36
|
+
reader = Fiber.new do
|
37
|
+
selector.io_wait(Fiber.current, input, IO::READABLE)
|
38
|
+
pp read: input.read
|
39
|
+
end
|
40
|
+
|
41
|
+
# The reader will be blocked until the IO has data available:
|
42
|
+
reader.transfer
|
43
|
+
|
44
|
+
# Write some data to the pipe and close the writing end:
|
45
|
+
writer.transfer
|
46
|
+
|
47
|
+
selector.select(1)
|
48
|
+
|
49
|
+
# Results in:
|
50
|
+
# {:read=>"Hello World"}
|
51
|
+
```
|
52
|
+
|
53
|
+
## Debugging
|
54
|
+
|
55
|
+
The {ruby IO::Event::Debug::Selector} class adds extra validations and checks at the expense of performance. It can also log all operations. You can use this by setting the following environment variables:
|
56
|
+
|
57
|
+
```shell
|
58
|
+
$ IO_EVENT_SELECTOR_DEBUG=y IO_EVENT_SELECTOR_DEBUG_LOG=/dev/stderr bundle exec ./my_script.rb
|
59
|
+
```
|
60
|
+
|
61
|
+
The format of the log is subject to change, but it may be useful for debugging.
|
data/context/index.yaml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Automatically generated context index for Utopia::Project guides.
|
2
|
+
# Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
|
3
|
+
---
|
4
|
+
description: An event loop.
|
5
|
+
metadata:
|
6
|
+
documentation_uri: https://socketry.github.io/io-event/
|
7
|
+
source_code_uri: https://github.com/socketry/io-event.git
|
8
|
+
files:
|
9
|
+
- path: getting-started.md
|
10
|
+
title: Getting Started
|
11
|
+
description: This guide explains how to use `io-event` for non-blocking IO.
|
data/ext/extconf.rb
CHANGED
@@ -19,7 +19,7 @@ append_cflags(["-Wall", "-Wno-unknown-pragmas", "-std=c99"])
|
|
19
19
|
|
20
20
|
if ENV.key?("RUBY_DEBUG")
|
21
21
|
$stderr.puts "Enabling debug mode..."
|
22
|
-
|
22
|
+
|
23
23
|
append_cflags(["-DRUBY_DEBUG", "-O0"])
|
24
24
|
end
|
25
25
|
|
@@ -33,7 +33,7 @@ have_func("&rb_fiber_transfer")
|
|
33
33
|
if have_library("uring") and have_header("liburing.h")
|
34
34
|
# We might want to consider using this in the future:
|
35
35
|
# have_func("io_uring_submit_and_wait_timeout", "liburing.h")
|
36
|
-
|
36
|
+
|
37
37
|
$srcs << "io/event/selector/uring.c"
|
38
38
|
end
|
39
39
|
|
@@ -70,7 +70,7 @@ end
|
|
70
70
|
|
71
71
|
if ENV.key?("RUBY_SANITIZE")
|
72
72
|
$stderr.puts "Enabling sanitizers..."
|
73
|
-
|
73
|
+
|
74
74
|
# Add address and undefined behaviour sanitizers:
|
75
75
|
append_cflags(["-fsanitize=address", "-fsanitize=undefined", "-fno-omit-frame-pointer"])
|
76
76
|
$LDFLAGS << " -fsanitize=address -fsanitize=undefined"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2021, by Wander Hillen.
|
5
|
-
# Copyright, 2021-
|
5
|
+
# Copyright, 2021-2025, by Samuel Williams.
|
6
6
|
|
7
7
|
class IO
|
8
8
|
module Event
|
@@ -28,6 +28,11 @@ class IO
|
|
28
28
|
@contents.size
|
29
29
|
end
|
30
30
|
|
31
|
+
# @returns [Boolean] true if the heap is empty, false otherwise.
|
32
|
+
def empty?
|
33
|
+
@contents.empty?
|
34
|
+
end
|
35
|
+
|
31
36
|
# Removes and returns the smallest element in the heap, or nil if the heap is empty.
|
32
37
|
#
|
33
38
|
# @returns [Object | Nil] The smallest element in the heap, or nil if the heap is empty.
|
data/lib/io/event/support.rb
CHANGED
data/lib/io/event/version.rb
CHANGED
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.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -55,6 +55,8 @@ extensions:
|
|
55
55
|
extra_rdoc_files: []
|
56
56
|
files:
|
57
57
|
- agent.md
|
58
|
+
- context/getting-started.md
|
59
|
+
- context/index.yaml
|
58
60
|
- design.md
|
59
61
|
- ext/extconf.rb
|
60
62
|
- ext/io/event/array.h
|
@@ -114,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
116
|
- !ruby/object:Gem::Version
|
115
117
|
version: '0'
|
116
118
|
requirements: []
|
117
|
-
rubygems_version: 3.6.
|
119
|
+
rubygems_version: 3.6.9
|
118
120
|
specification_version: 4
|
119
121
|
summary: An event loop.
|
120
122
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|