goru 0.1.0 → 0.2.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
- data/CHANGELOG.md +10 -0
- data/README.md +1 -21
- data/lib/goru/channel.rb +1 -8
- data/lib/goru/routine.rb +13 -6
- data/lib/goru/routines/bridge.rb +0 -4
- data/lib/goru/routines/bridges/readable.rb +1 -1
- data/lib/goru/routines/channel.rb +0 -4
- data/lib/goru/routines/channels/writable.rb +1 -1
- data/lib/goru/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de298097d409c1186dd803f5748a1af3820c23ea0a7243e1d18c42ef35229906
|
4
|
+
data.tar.gz: d834815e8f7f1a0deb22ad6be3cb8c75d900f81b5ffae1e55ce8eb10ef78bb3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8674505286bace79c7b462ccf6c8b779f3b8ba09b7ca16b02a657d11f803a1f45835d286385b59e50b3909eced44e7ce6601db957b20c62737df96b13a24d564
|
7
|
+
data.tar.gz: 353c05c439a9a85aedd2727f6036b8b858e59dd73f5c29acc4291b9533a78d45b375a8e07e57cc3e57765c974c584bc1aa09304e101fecb38652f8f47d8e588d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.2.0
|
2
|
+
|
3
|
+
*unreleased*
|
4
|
+
|
5
|
+
* `fix` [#6](https://github.com/bryanp/goru/pull/6) Finish routines on error ([bryanp](https://github.com/bryanp))
|
6
|
+
* `fix` [#5](https://github.com/bryanp/goru/pull/5) Correctly set channel status to `finished` when closed ([bryanp](https://github.com/bryanp))
|
7
|
+
* `chg` [#4](https://github.com/bryanp/goru/pull/4) Only log when routines are in debug mode ([bryanp](https://github.com/bryanp))
|
8
|
+
* `fix` [#3](https://github.com/bryanp/goru/pull/3) Update `Goru::Channel#full?` to always return a boolean ([bryanp](https://github.com/bryanp))
|
9
|
+
* `dep` [#2](https://github.com/bryanp/goru/pull/2) Remove ability to reopen channels ([bryanp](https://github.com/bryanp))
|
10
|
+
|
1
11
|
## [v0.1.0](https://github.com/bryanp/goru/releases/tag/v0.1.0)
|
2
12
|
|
3
13
|
*released on 2023-03-29*
|
data/README.md
CHANGED
@@ -122,8 +122,6 @@ Goru::Scheduler.go { |routine|
|
|
122
122
|
}
|
123
123
|
```
|
124
124
|
|
125
|
-
See [`core-handler`](https://github.com/bryanp/corerb/tree/main/handler) for more about error handling.
|
126
|
-
|
127
125
|
## Sleeping
|
128
126
|
|
129
127
|
Goru implements a non-blocking version of `sleep` that makes the routine ineligible to be called until the sleep time
|
@@ -176,7 +174,7 @@ Goru includes a pattern for non-blocking io. With it you can implement non-block
|
|
176
174
|
Routines that involve io must be created with an io object and an intent. Possible intents include:
|
177
175
|
|
178
176
|
* `:r` for reading
|
179
|
-
* `:
|
177
|
+
* `:w` for writing
|
180
178
|
* `:rw` for reading and writing
|
181
179
|
|
182
180
|
Here is the beginning of an http server in Goru:
|
@@ -203,24 +201,6 @@ Goru::Scheduler.go(io: io, intent: :r) { |routine|
|
|
203
201
|
}
|
204
202
|
```
|
205
203
|
|
206
|
-
## Bridges
|
207
|
-
|
208
|
-
Goru supports coordinates buffered io using bridges:
|
209
|
-
|
210
|
-
```ruby
|
211
|
-
writer = Goru::Channel.new
|
212
|
-
|
213
|
-
Goru::Scheduler.go(io: io, intent: :w) { |routine|
|
214
|
-
routine.bridge(writer, intent: :w)
|
215
|
-
}
|
216
|
-
|
217
|
-
Goru::Scheduler.go(channel: writer) { |routine|
|
218
|
-
routine << SecureRandom.hex
|
219
|
-
}
|
220
|
-
```
|
221
|
-
|
222
|
-
This allows routines to easily write data to a buffer independently of how the data is written to io.
|
223
|
-
|
224
204
|
## Credits
|
225
205
|
|
226
206
|
Goru was designed while writing a project in Go and imagining what Go-like concurrency might look like in Ruby.
|
data/lib/goru/channel.rb
CHANGED
@@ -46,7 +46,7 @@ module Goru
|
|
46
46
|
# [public]
|
47
47
|
#
|
48
48
|
def full?
|
49
|
-
|
49
|
+
!!@size && @messages.size == @size
|
50
50
|
end
|
51
51
|
|
52
52
|
# [public]
|
@@ -62,13 +62,6 @@ module Goru
|
|
62
62
|
@observers.each(&:channel_closed)
|
63
63
|
end
|
64
64
|
|
65
|
-
# [public]
|
66
|
-
#
|
67
|
-
def reopen
|
68
|
-
@closed = false
|
69
|
-
@observers.each(&:channel_reopened)
|
70
|
-
end
|
71
|
-
|
72
65
|
# [public]
|
73
66
|
#
|
74
67
|
def clear
|
data/lib/goru/routine.rb
CHANGED
@@ -9,10 +9,12 @@ module Goru
|
|
9
9
|
include Is::Handler
|
10
10
|
|
11
11
|
handle(StandardError) do |event:|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if @debug
|
13
|
+
$stderr << <<~ERROR
|
14
|
+
[goru] routine crashed: #{event}
|
15
|
+
#{event.backtrace.join("\n")}
|
16
|
+
ERROR
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def initialize(state = nil, &block)
|
@@ -20,11 +22,16 @@ module Goru
|
|
20
22
|
@block = block
|
21
23
|
set_status(:ready)
|
22
24
|
@result, @error, @reactor = nil
|
25
|
+
@debug = true
|
23
26
|
end
|
24
27
|
|
25
28
|
# [public]
|
26
29
|
#
|
27
|
-
attr_reader :state, :status
|
30
|
+
attr_reader :state, :status, :error
|
31
|
+
|
32
|
+
# [public]
|
33
|
+
#
|
34
|
+
attr_writer :debug
|
28
35
|
|
29
36
|
# [public]
|
30
37
|
#
|
@@ -93,7 +100,7 @@ module Goru
|
|
93
100
|
#
|
94
101
|
private def status_changed
|
95
102
|
case @status
|
96
|
-
when :finished
|
103
|
+
when :errored, :finished
|
97
104
|
@reactor&.routine_finished(self)
|
98
105
|
end
|
99
106
|
end
|
data/lib/goru/routines/bridge.rb
CHANGED
data/lib/goru/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: core-extension
|