goru 0.1.0 → 0.2.0

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: 5a78af9c418381f52acab486a5f32205f6ce73fdaf4327954fe551e6ca919b21
4
- data.tar.gz: 1185292bd3717ea47388afaa5bd3a914c869ff8ff07132e80b0f118a03e8eff1
3
+ metadata.gz: de298097d409c1186dd803f5748a1af3820c23ea0a7243e1d18c42ef35229906
4
+ data.tar.gz: d834815e8f7f1a0deb22ad6be3cb8c75d900f81b5ffae1e55ce8eb10ef78bb3e
5
5
  SHA512:
6
- metadata.gz: 5ea306fe3b3445a1eabfbfffc4f80d572f9dcecaee129cf2e28bc65e207f3b82b06d355d52431993765703c7e6e8fb959d5ea2886292160b96e781eb8fab48a3
7
- data.tar.gz: 497417e7c3dac2ab8454878e4cb869de978942d0bc60b14a908191d84d59be27a514373543f1fe431089eb0393157ae919941dfe210c1b6256f10ea6a5f7c54f
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
- * `:r` for writing
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
- @size && @messages.size == @size
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
- $stderr << <<~ERROR
13
- [goru] routine crashed: #{event}
14
- #{event.backtrace.join("\n")}
15
- ERROR
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
@@ -41,10 +41,6 @@ module Goru
41
41
  def channel_closed
42
42
  update_status
43
43
  end
44
-
45
- def channel_reopened
46
- update_status
47
- end
48
44
  end
49
45
  end
50
46
  end
@@ -24,7 +24,7 @@ module Goru
24
24
  elsif @channel.full?
25
25
  :idle
26
26
  elsif @channel.closed?
27
- :idle
27
+ :finished
28
28
  else
29
29
  :ready
30
30
  end
@@ -36,10 +36,6 @@ module Goru
36
36
  def channel_closed
37
37
  update_status
38
38
  end
39
-
40
- def channel_reopened
41
- update_status
42
- end
43
39
  end
44
40
  end
45
41
  end
@@ -24,7 +24,7 @@ module Goru
24
24
  status = if @channel.full?
25
25
  :idle
26
26
  elsif @channel.closed?
27
- :idle
27
+ :finished
28
28
  else
29
29
  :ready
30
30
  end
data/lib/goru/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Goru
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
 
6
6
  # [public]
7
7
  #
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.1.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-03-30 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension