polyphony 1.1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/.github/workflows/test_io_uring.yml +1 -1
  4. data/.rubocop.yml +16 -8
  5. data/CHANGELOG.md +9 -0
  6. data/README.md +2 -1
  7. data/docs/advanced-io.md +9 -1
  8. data/docs/cancellation.md +213 -0
  9. data/docs/readme.md +2 -1
  10. data/examples/core/enumerator.rb +92 -0
  11. data/examples/io/https_server_sni_2.rb +1 -1
  12. data/ext/polyphony/backend_common.c +11 -0
  13. data/ext/polyphony/backend_common.h +2 -0
  14. data/ext/polyphony/backend_io_uring.c +1 -1
  15. data/ext/polyphony/backend_libev.c +1 -1
  16. data/ext/polyphony/polyphony.h +3 -1
  17. data/lib/polyphony/core/debug.rb +24 -29
  18. data/lib/polyphony/core/exceptions.rb +0 -3
  19. data/lib/polyphony/core/sync.rb +0 -3
  20. data/lib/polyphony/core/thread_pool.rb +1 -5
  21. data/lib/polyphony/core/throttler.rb +0 -1
  22. data/lib/polyphony/core/timer.rb +7 -9
  23. data/lib/polyphony/extensions/exception.rb +0 -1
  24. data/lib/polyphony/extensions/fiber.rb +41 -28
  25. data/lib/polyphony/extensions/io.rb +86 -93
  26. data/lib/polyphony/extensions/kernel.rb +52 -16
  27. data/lib/polyphony/extensions/object.rb +7 -6
  28. data/lib/polyphony/extensions/openssl.rb +6 -8
  29. data/lib/polyphony/extensions/pipe.rb +5 -7
  30. data/lib/polyphony/extensions/socket.rb +28 -37
  31. data/lib/polyphony/extensions/thread.rb +2 -4
  32. data/lib/polyphony/extensions/timeout.rb +0 -1
  33. data/lib/polyphony/version.rb +1 -1
  34. data/lib/polyphony.rb +4 -7
  35. data/polyphony.gemspec +1 -1
  36. data/test/test_fiber.rb +6 -6
  37. data/test/test_global_api.rb +3 -3
  38. data/test/test_io.rb +2 -2
  39. data/test/test_socket.rb +2 -2
  40. data/test/test_supervise.rb +1 -1
  41. metadata +5 -3
data/lib/polyphony.rb CHANGED
@@ -60,7 +60,7 @@ module Polyphony
60
60
  rescue Polyphony::MoveOn
61
61
  exit!
62
62
  rescue Exception => e
63
- STDERR << e.full_message
63
+ $stderr << e.full_message
64
64
  exit!
65
65
  ensure
66
66
  exit_forked_process
@@ -92,8 +92,8 @@ module Polyphony
92
92
  # @!visibility private
93
93
  def install_terminating_signal_handlers
94
94
  trap('SIGTERM') { raise SystemExit }
95
- orig_trap('SIGINT') do
96
- orig_trap('SIGINT') { exit! }
95
+ Kernel.orig_trap('SIGINT') do
96
+ Kernel.orig_trap('SIGINT') { exit! }
97
97
  Fiber.schedule_priority_oob_fiber { raise Interrupt }
98
98
  end
99
99
  end
@@ -143,13 +143,10 @@ module Polyphony
143
143
  install_at_exit_handler
144
144
  end
145
145
 
146
-
147
146
  if (debug_socket_path = ENV['POLYPHONY_DEBUG_SOCKET_PATH'])
148
147
  puts "Starting debug server on #{debug_socket_path}"
149
148
  require 'polyphony/debugger'
150
149
  Polyphony.start_debug_server(debug_socket_path)
151
150
  end
152
151
 
153
- if Object.const_defined?(:IRB)
154
- require_relative './polyphony/adapters/irb'
155
- end
152
+ require_relative './polyphony/adapters/irb' if Object.const_defined?(:IRB)
data/polyphony.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.extra_rdoc_files = ["README.md"]
19
19
  s.extensions = ["ext/polyphony/extconf.rb"]
20
20
  s.require_paths = ["lib"]
21
- s.required_ruby_version = '>= 3.0'
21
+ s.required_ruby_version = '>= 3.1'
22
22
 
23
23
  s.add_development_dependency 'rake-compiler', '1.2.1'
24
24
  s.add_development_dependency 'minitest', '5.17.0'
data/test/test_fiber.rb CHANGED
@@ -987,7 +987,7 @@ class MailboxTest < MiniTest::Test
987
987
  f << :foo
988
988
  snooze
989
989
  assert_equal [:foo], buffer
990
-
990
+
991
991
  f << :bar
992
992
  snooze
993
993
  assert_equal [:foo, :bar], buffer
@@ -1011,7 +1011,7 @@ class MailboxTest < MiniTest::Test
1011
1011
  f << :foo
1012
1012
  snooze
1013
1013
  assert_equal [:foo], buffer
1014
-
1014
+
1015
1015
  f << :bar
1016
1016
  snooze
1017
1017
  assert_equal [:foo, :bar, :done], buffer
@@ -1264,7 +1264,7 @@ class GracefulTerminationTest < MiniTest::Test
1264
1264
  end
1265
1265
 
1266
1266
  3.times { snooze }
1267
- f.terminate(false)
1267
+ f.terminate(graceful: false)
1268
1268
  f.await
1269
1269
  assert_equal [1, 2], buffer
1270
1270
 
@@ -1280,7 +1280,7 @@ class GracefulTerminationTest < MiniTest::Test
1280
1280
  end
1281
1281
 
1282
1282
  3.times { snooze }
1283
- f.terminate(true)
1283
+ f.terminate(graceful: true)
1284
1284
  f.await
1285
1285
  assert_equal [1, 2, 4], buffer
1286
1286
  end
@@ -1302,12 +1302,12 @@ class GracefulTerminationTest < MiniTest::Test
1302
1302
 
1303
1303
  sleep
1304
1304
  ensure
1305
- Fiber.current.terminate_all_children(true) if Fiber.current.graceful_shutdown?
1305
+ Fiber.current.terminate_all_children(graceful: true) if Fiber.current.graceful_shutdown?
1306
1306
  Fiber.current.await_all_children
1307
1307
  end
1308
1308
 
1309
1309
  3.times { snooze }
1310
- f0.terminate(true)
1310
+ f0.terminate(graceful: true)
1311
1311
  f0.await
1312
1312
 
1313
1313
  assert_equal [1, 2], buffer
@@ -129,15 +129,15 @@ class MoveOnAfterTest < MiniTest::Test
129
129
  def test_move_on_after_with_reset
130
130
  t0 = monotonic_clock
131
131
  v = move_on_after(0.01, with_value: :moved_on) do |timeout|
132
- sleep 0.007
132
+ sleep 0.006
133
133
  timeout.reset
134
- sleep 0.007
134
+ sleep 0.006
135
135
  nil
136
136
  end
137
137
  t1 = monotonic_clock
138
138
 
139
139
  assert_nil v
140
- assert_in_range 0.014..0.025, t1 - t0 if IS_LINUX
140
+ assert_in_range 0.012..0.025, t1 - t0 if IS_LINUX
141
141
  end
142
142
 
143
143
  def test_nested_move_on_after
data/test/test_io.rb CHANGED
@@ -89,7 +89,7 @@ class IOTest < MiniTest::Test
89
89
 
90
90
  buf = +'def'
91
91
  o << 'foobar'
92
- assert_equal 'deffoobar', i.read(6, buf, -1)
92
+ assert_equal 'deffoobar', i.read(6, buf, buffer_pos: -1)
93
93
  assert_equal 'deffoobar', buf
94
94
  end
95
95
 
@@ -332,7 +332,7 @@ class IOTest < MiniTest::Test
332
332
  splice_lens << len
333
333
  break if len == 0
334
334
  }
335
-
335
+
336
336
  o2.close
337
337
  }
338
338
 
data/test/test_socket.rb CHANGED
@@ -98,7 +98,7 @@ class TCPSocketTest < MiniTest::Test
98
98
 
99
99
  buf = +'def'
100
100
  client << 'foobar'
101
- assert_equal 'deffoobar', client.read(6, buf, -1)
101
+ assert_equal 'deffoobar', client.read(6, buf, buffer_pos: -1)
102
102
  assert_equal 'deffoobar', buf
103
103
 
104
104
  client.close
@@ -365,7 +365,7 @@ class SSLSocketTest < MiniTest::Test
365
365
  f = spin do
366
366
  ## without ignoring errors
367
367
  f2 = spin do
368
- server.accept_loop(false) { |s| handle_http_request(s) }
368
+ server.accept_loop(ignore_errors: false) { |s| handle_http_request(s) }
369
369
  end
370
370
  f2.await
371
371
  rescue => e
@@ -289,7 +289,7 @@ class SuperviseTest < MiniTest::Test
289
289
  s = spin { supervise }.detach
290
290
  Fiber.current.attach_all_children_to(s)
291
291
 
292
- s.terminate(true)
292
+ s.terminate(graceful: true)
293
293
  }
294
294
 
295
295
  f.await
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyphony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -183,6 +183,7 @@ files:
183
183
  - docs/assets/echo-fibers.svg
184
184
  - docs/assets/polyphony-logo.png
185
185
  - docs/assets/sleeping-fiber.svg
186
+ - docs/cancellation.md
186
187
  - docs/cheat-sheet.md
187
188
  - docs/concurrency.md
188
189
  - docs/design-principles.md
@@ -214,6 +215,7 @@ files:
214
215
  - examples/core/debug.rb
215
216
  - examples/core/deferring-an-operation.rb
216
217
  - examples/core/enumerable.rb
218
+ - examples/core/enumerator.rb
217
219
  - examples/core/erlang-style-genserver.rb
218
220
  - examples/core/forking.rb
219
221
  - examples/core/handling-signals.rb
@@ -666,7 +668,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
666
668
  requirements:
667
669
  - - ">="
668
670
  - !ruby/object:Gem::Version
669
- version: '3.0'
671
+ version: '3.1'
670
672
  required_rubygems_version: !ruby/object:Gem::Requirement
671
673
  requirements:
672
674
  - - ">="