uringmachine 0.28.2 → 0.28.3
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
- data/CHANGELOG.md +4 -0
- data/TODO.md +31 -0
- data/ext/um/um.c +1 -1
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fbdc1ca412e20436a209c2e4f77af29873d5c8bac02f88c35562333f1e5328e6
|
|
4
|
+
data.tar.gz: d426661ce83c278041042c5829a23b4bb5c0c65cf99d1cb3cb96f5706b464859
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9908398a698bf7a2771a88b369023e27c3669bd205eb86a8132fee154709d68b21cd05a4fcd8b0bacb0f8e10140f2a2ef002f01cd7ac8177bf678c4f8e8574b5
|
|
7
|
+
data.tar.gz: afb606febf25d41fdf99b00e8cdeaa97523608445cc842cf49acbdf5af95f726276d443a574363b23b9b6c8287fad560780913f4bf1fd09240cf5df29185a9ac
|
data/CHANGELOG.md
CHANGED
data/TODO.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
## immediate
|
|
2
2
|
|
|
3
|
+
- Add support for exception instances in `#timeout`.
|
|
4
|
+
- Add support for returning a value on timeout:
|
|
5
|
+
|
|
6
|
+
Since to do this safely we need to actually raise an exception that wraps the
|
|
7
|
+
value, rescue it and return the value, we might want a separate method that
|
|
8
|
+
wraps `#timeout`:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
TimeoutValueError < StandardError
|
|
12
|
+
|
|
13
|
+
def timeout_with_value(interval, value, &block)
|
|
14
|
+
timeout_error = TimeoutValueError
|
|
15
|
+
timeout(interval, timeout_error, &block)
|
|
16
|
+
rescue TimeoutValueError => e
|
|
17
|
+
raise if e != timeout_error
|
|
18
|
+
|
|
19
|
+
value
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
3
23
|
- Add tests for support for Set in `machine#await_fibers`
|
|
4
24
|
- Add tests for support for Set, Array in `machine#join`
|
|
5
25
|
- Add `#read_file` for reading entire file
|
|
@@ -145,3 +165,14 @@ jobs = (1..100).map { |i|
|
|
|
145
165
|
}
|
|
146
166
|
machine.join(jobs)
|
|
147
167
|
```
|
|
168
|
+
|
|
169
|
+
## Other abstractions
|
|
170
|
+
|
|
171
|
+
- Happy eyeballs connect
|
|
172
|
+
|
|
173
|
+
```ruby
|
|
174
|
+
# addrs: [['1.1.1.1', 80], ['2.2.2.2', 80]]
|
|
175
|
+
# ['1.1.1.1:80', '2.2.2.2:80']
|
|
176
|
+
tcp_connect_happy_eyeballs(*addrs)
|
|
177
|
+
```
|
|
178
|
+
|
data/ext/um/um.c
CHANGED
|
@@ -539,7 +539,7 @@ VALUE um_timeout_complete(VALUE arg) {
|
|
|
539
539
|
|
|
540
540
|
VALUE um_timeout(struct um *machine, VALUE interval, VALUE class) {
|
|
541
541
|
static ID ID_new = 0;
|
|
542
|
-
if (!ID_new) ID_new = rb_intern("new");
|
|
542
|
+
if (unlikely(!ID_new)) ID_new = rb_intern("new");
|
|
543
543
|
|
|
544
544
|
struct um_op *op = um_op_acquire(machine);
|
|
545
545
|
um_prep_op(machine, op, OP_TIMEOUT, 2, 0);
|
data/lib/uringmachine/version.rb
CHANGED
data/lib/uringmachine.rb
CHANGED
|
@@ -36,9 +36,17 @@ class UringMachine
|
|
|
36
36
|
fiber
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
TERMINATE_EXCEPTION = UM::Terminate.new
|
|
40
|
+
|
|
41
|
+
# Terminates the given fibers by scheduling them with a `UM::Terminate`
|
|
42
|
+
# exception. This method does not wait for the fibers to be done.
|
|
43
|
+
#
|
|
44
|
+
# @param *fibers [Array<Fiber>] fibers to terminate
|
|
45
|
+
# @return [void]
|
|
39
46
|
def terminate(*fibers)
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
fibers = fibers.first if fibers.size == 1 && fibers.first.is_a?(Enumerable)
|
|
48
|
+
|
|
49
|
+
fibers.each { schedule(it, TERMINATE_EXCEPTION) }
|
|
42
50
|
end
|
|
43
51
|
|
|
44
52
|
# Runs the given block in the given fiber. This method is used to run fibers
|
|
@@ -58,6 +66,8 @@ class UringMachine
|
|
|
58
66
|
#
|
|
59
67
|
# @return [Array<any>] return values of the given fibers
|
|
60
68
|
def join(*fibers)
|
|
69
|
+
fibers = fibers.first if fibers.size == 1 && fibers.first.is_a?(Enumerable)
|
|
70
|
+
|
|
61
71
|
results = fibers.inject({}) { |h, f| h[f] = nil; h }
|
|
62
72
|
queue = nil
|
|
63
73
|
pending = nil
|