polyphony 0.99.5 → 0.99.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d73317fd0bed90e2966bcf71e0f89d13318c21a4d235127162c3ed1d4f7ee2ea
4
- data.tar.gz: bad470bf595168aec1e8cac95b6b707d82a1f10a4e9c2cdc33d35194d0bb4a53
3
+ metadata.gz: 4a2733c956cab37dac192c107c4c2def808595601cca177dfbfcbd23b3b291e7
4
+ data.tar.gz: 417aacff2dac6ec2f4cfe85c8afc0bab21a5d20ac8748a3a5ceca42ec7950b8c
5
5
  SHA512:
6
- metadata.gz: 7e64aafec751da5932e1782acd28a29c6661ae76a223b9edaa6445b1d4c2728b2a185a98b86d4d87ace5ca35522030d68b902b0679c95dfd82783e3f12d8d9a8
7
- data.tar.gz: bdac913bc057e31cb51f47b6624e62e59f071db050480a64f73a5273a187243944487df86383d4970e1082a2032f624205791ab7b43f98f64385bccf6918ac8a
6
+ metadata.gz: 7c5d41ad9927a1b3770b76b702bc3f7695d4fb0c87601df3a5fd9d25cdc3e121881ec4e9dbbe618234864c73b8ac67cf1f9156a5bc031a7186d9633a03d70e00
7
+ data.tar.gz: ad66aab4d2fb6b60f702791036fa8883b6e262eadee7170dc285d68903b2447d17160aec9e382c336ace24e3e0379d25683ba736084df6c61c36858b465513e4
data/.rubocop.yml CHANGED
@@ -99,6 +99,7 @@ Metrics/ClassLength:
99
99
  - lib/polyphony/http/server/http1.rb
100
100
  - lib/polyphony/extensions/io.rb
101
101
  - lib/polyphony/extensions/fiber.rb
102
+ - lib/polyphony/extensions/object.rb
102
103
  - test/**/*.rb
103
104
  - examples/**/*.rb
104
105
 
data/.yardopts CHANGED
@@ -3,7 +3,6 @@
3
3
  --verbose
4
4
  --protected
5
5
  --no-private
6
- --asset assets/:assets
7
6
  --exclude debugger.rb
8
7
  --exclude redis.rb
9
8
  --exclude readline.rb
@@ -14,7 +13,6 @@
14
13
  --exclude sequel.rb
15
14
  --exclude event.c
16
15
  --exclude backend.+\.c
17
- # --load ./docs/link_rewriter.rb
18
16
  -r docs/readme.md
19
17
  ./lib
20
18
  ./ext/polyphony
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <img src="https://github.com/digital-fabric/polyphony/raw/master/assets/polyphony-logo.png">
1
+ <img src="https://github.com/digital-fabric/polyphony/raw/master/docs/assets/polyphony-logo.png">
2
2
 
3
3
  # Polyphony: Fine-Grained Concurrency for Ruby
4
4
 
data/docs/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @title README
2
2
 
3
- <img src="https://github.com/digital-fabric/polyphony/raw/master/assets/polyphony-logo.png">
3
+ <img src="https://github.com/digital-fabric/polyphony/raw/master/docs/assets/polyphony-logo.png">
4
4
 
5
5
  # Polyphony: Fine-Grained Concurrency for Ruby
6
6
 
data/docs/tutorial.md CHANGED
@@ -94,7 +94,7 @@ The above program does nothing exceptional, it just sleeps for 1 second and
94
94
  prints a bunch of messages. But it is enough to demonstrate how concurrency
95
95
  works in Polyphony. Here's a flow chart of the transfer of control:
96
96
 
97
- <img src="../assets/sleeping-fiber.svg">
97
+ <img src="https://github.com/digital-fabric/polyphony/raw/master/docs/assets/sleeping-fiber.png">
98
98
 
99
99
  Here's the actual sequence of execution (in pseudo-code)
100
100
 
@@ -189,7 +189,7 @@ innocent call to `#spin`.
189
189
 
190
190
  Here's a flow chart showing the transfer of control between the different fibers:
191
191
 
192
- <img src="../assets/echo-fibers.svg">
192
+ <img src="https://github.com/digital-fabric/polyphony/raw/master/docs/assets/echo-fibers.png">
193
193
 
194
194
  Let's consider the advantage of the Polyphony concurrency model:
195
195
 
@@ -116,7 +116,7 @@ static VALUE Fiber_state(VALUE self) {
116
116
  * mailbox.
117
117
  *
118
118
  * @param msg [any]
119
- * @return [void]
119
+ * @return [Fiber] self
120
120
  */
121
121
 
122
122
  VALUE Fiber_send(VALUE self, VALUE msg) {
data/ext/polyphony/pipe.c CHANGED
@@ -37,8 +37,6 @@ static VALUE Pipe_allocate(VALUE klass) {
37
37
  TypedData_Get_Struct((obj), Pipe_t, &Pipe_type, (pipe))
38
38
 
39
39
  /* Creates a new pipe.
40
- *
41
- * @return [void]
42
40
  */
43
41
 
44
42
  static VALUE Pipe_initialize(VALUE self) {
@@ -32,7 +32,7 @@ ID ID_RW;
32
32
  * current fiber eventually continue its work. This call is useful when
33
33
  * performing long-running calculations in order to keep the program responsive.
34
34
  *
35
- * @return [void]
35
+ * @return [any] resume value
36
36
  */
37
37
 
38
38
  VALUE Polyphony_snooze(VALUE self) {
@@ -43,7 +43,7 @@ VALUE Polyphony_snooze(VALUE self) {
43
43
  * rescheduling the current fiber. This is useful if the current fiber does not
44
44
  * need to continue or will be scheduled by other means eventually.
45
45
  *
46
- * @return [void]
46
+ * @return [any] resume value
47
47
  */
48
48
 
49
49
  static VALUE Polyphony_suspend(VALUE self) {
@@ -73,7 +73,7 @@ VALUE Polyphony_backend_accept(VALUE self, VALUE server_socket, VALUE socket_cla
73
73
  * @param server_socket [Socket] socket to accept on
74
74
  * @param socket_class [Class] class of the socket to instantiate for the accepted connection
75
75
  * @yield [Socket] accepted connection
76
- * @return [void]
76
+ * @return [nil]
77
77
  */
78
78
 
79
79
  VALUE Polyphony_backend_accept_loop(VALUE self, VALUE server_socket, VALUE socket_class) {
@@ -85,7 +85,7 @@ VALUE Polyphony_backend_accept_loop(VALUE self, VALUE server_socket, VALUE socke
85
85
  * available only for the io_uring backend.
86
86
  *
87
87
  * @param server_socket [Socket] socket to accept on
88
- * @return [void]
88
+ * @return [any] block return value
89
89
  */
90
90
 
91
91
  VALUE Polyphony_backend_multishot_accept(VALUE self, VALUE server_socket) {
@@ -143,7 +143,7 @@ VALUE Polyphony_backend_read(VALUE self, VALUE io, VALUE buffer, VALUE length, V
143
143
  * @param io [IO] io to read from
144
144
  * @param maxlen [Integer] maximum bytes to read
145
145
  *
146
- * @return [void]
146
+ * @return [IO] io
147
147
  */
148
148
 
149
149
  VALUE Polyphony_backend_read_loop(VALUE self, VALUE io, VALUE maxlen) {
@@ -186,7 +186,7 @@ VALUE Polyphony_backend_recvmsg(VALUE self, VALUE socket, VALUE buffer, VALUE ma
186
186
  * @param socket [Socket] socket to receive on
187
187
  * @param maxlen [Integer] maximum bytes to read
188
188
  * @yield [data] received data
189
- * @return [void]
189
+ * @return [Socket] socket
190
190
  */
191
191
 
192
192
  VALUE Polyphony_backend_recv_loop(VALUE self, VALUE socket, VALUE maxlen) {
@@ -202,7 +202,7 @@ VALUE Polyphony_backend_recv_loop(VALUE self, VALUE socket, VALUE maxlen) {
202
202
  * @param receiver [any] an object receiving the data
203
203
  * @param method [Symbol] method used to feed the data to the receiver
204
204
  *
205
- * @return [void]
205
+ * @return [Socket] socket
206
206
  */
207
207
 
208
208
  VALUE Polyphony_backend_recv_feed_loop(VALUE self, VALUE socket, VALUE receiver, VALUE method) {
@@ -252,7 +252,7 @@ VALUE Polyphony_backend_sendv(VALUE self, VALUE socket, VALUE ary, VALUE flags)
252
252
  /* Sleeps for the given duration, yielding execution to other fibers.
253
253
  *
254
254
  * @param duration [Number] duration in seconds
255
- * @return [void]
255
+ * @return [nil]
256
256
  */
257
257
 
258
258
  VALUE Polyphony_backend_sleep(VALUE self, VALUE duration) {
@@ -308,7 +308,6 @@ VALUE Polyphony_backend_timeout(int argc,VALUE *argv, VALUE self) {
308
308
  /* Runs an infinite loop that calls the given block at the specified time interval.
309
309
  *
310
310
  * @param interval [Number] interval in seconds
311
- * @return [void]
312
311
  */
313
312
 
314
313
  VALUE Polyphony_backend_timer_loop(VALUE self, VALUE interval) {
@@ -320,7 +319,6 @@ VALUE Polyphony_backend_timer_loop(VALUE self, VALUE interval) {
320
319
  * exception will be raised.
321
320
  *
322
321
  * @param raise [boolean]
323
- * @return [any] resumed value
324
322
  */
325
323
 
326
324
  VALUE Polyphony_backend_wait_event(VALUE self, VALUE raise) {
@@ -332,7 +330,7 @@ VALUE Polyphony_backend_wait_event(VALUE self, VALUE raise) {
332
330
  *
333
331
  * @param io [IO]
334
332
  * @param write [boolean] false for read, true for write
335
- * @return [void]
333
+ * @return [nil]
336
334
  */
337
335
 
338
336
  VALUE Polyphony_backend_wait_io(VALUE self, VALUE io, VALUE write) {
@@ -67,10 +67,8 @@ static VALUE Queue_allocate(VALUE klass) {
67
67
  * until at least one item is removed from the queue.
68
68
  *
69
69
  * @overload new()
70
- * @return [void]
71
70
  * @overload new(capacity)
72
71
  * @param capacity [Integer] maximum items in queue
73
- * @return [void]
74
72
  */
75
73
 
76
74
  static VALUE Queue_initialize(int argc, VALUE *argv, VALUE self) {
@@ -44,7 +44,7 @@ inline void Thread_schedule_fiber_with_priority(VALUE self, VALUE fiber, VALUE v
44
44
 
45
45
  /* Switches to the next fiber in the thread's runqueue.
46
46
  *
47
- * @return [void]
47
+ * @return [any] resume value
48
48
  */
49
49
 
50
50
  VALUE Thread_switch_fiber(VALUE self) {
@@ -13,7 +13,7 @@ module Polyphony
13
13
  # process is killed.
14
14
  #
15
15
  # @param cmd [String, nil] command to spawn
16
- # @return [void]
16
+ # @return [true]
17
17
  def watch(cmd = nil, &block)
18
18
  terminated = nil
19
19
  pid = cmd ? Kernel.spawn(cmd) : Polyphony.fork(&block)
@@ -27,7 +27,6 @@ module Polyphony
27
27
  # seconds.
28
28
  #
29
29
  # @param pid [Integer] pid
30
- # @return [void]
31
30
  def kill_process(pid)
32
31
  cancel_after(5) do
33
32
  kill_and_await('TERM', pid)
@@ -42,7 +41,6 @@ module Polyphony
42
41
  #
43
42
  # @param sig [String, Symbol, Integer] signal to use
44
43
  # @param pid [Integer] pid
45
- # @return [void]
46
44
  def kill_and_await(sig, pid)
47
45
  ::Process.kill(sig, pid)
48
46
  Polyphony.backend_waitpid(pid)
@@ -1,8 +1,6 @@
1
1
  # Kernel extensions
2
2
  module ::Kernel
3
3
  # Prints a trace message to `STDOUT`, bypassing the Polyphony backend.
4
- #
5
- # @return [void]
6
4
  def trace(*args)
7
5
  STDOUT.orig_write(format_trace(args))
8
6
  end
@@ -33,7 +31,6 @@ module Polyphony
33
31
  #
34
32
  # @param io [IO, nil] IO instance
35
33
  # @yield [Hash] event information
36
- # @return [void]
37
34
  def start_event_firehose(io = nil, &block)
38
35
  Thread.backend.trace_proc = firehose_proc(io, block)
39
36
  end
@@ -16,7 +16,6 @@ module Polyphony
16
16
  # Initializes the exception, setting the caller and the value.
17
17
  #
18
18
  # @param value [any] Exception value
19
- # @return [void]
20
19
  def initialize(value = nil)
21
20
  @caller_backtrace = caller
22
21
  @value = value
@@ -44,14 +43,11 @@ module Polyphony
44
43
  # Initializes an Interjection with the given proc.
45
44
  #
46
45
  # @param proc [Proc] interjection proc
47
- # @return [void]
48
46
  def initialize(proc)
49
47
  @proc = proc
50
48
  end
51
49
 
52
50
  # Invokes the exception by calling the associated proc.
53
- #
54
- # @return [void]
55
51
  def invoke
56
52
  @proc.call
57
53
  end
@@ -27,7 +27,7 @@ module Polyphony
27
27
  # Conditionally releases the mutex. This method is used by condition
28
28
  # variables.
29
29
  #
30
- # @return [void]
30
+ # @return [nil]
31
31
  def conditional_release
32
32
  @store << @token
33
33
  @token = nil
@@ -37,7 +37,7 @@ module Polyphony
37
37
  # Conditionally reacquires the mutex. This method is used by condition
38
38
  # variables.
39
39
  #
40
- # @return [void]
40
+ # @return [Fiber] current fiber
41
41
  def conditional_reacquire
42
42
  @token = @store.shift
43
43
  @holding_fiber = Fiber.current
@@ -140,7 +140,7 @@ module Polyphony
140
140
  #
141
141
  # @param mutex [Polyphony::Mutex] mutex to release while waiting for signal
142
142
  # @param _timeout [Number, nil] timeout in seconds (currently not implemented)
143
- # @return [void]
143
+ # @return [any]
144
144
  def wait(mutex, _timeout = nil)
145
145
  mutex.conditional_release
146
146
  @queue << Fiber.current
@@ -151,7 +151,7 @@ module Polyphony
151
151
  # Signals the condition variable, causing the first fiber in the waiting
152
152
  # queue to be resumed.
153
153
  #
154
- # @return [void]
154
+ # @return [Fiber] resumed fiber
155
155
  def signal
156
156
  return if @queue.empty?
157
157
 
@@ -160,8 +160,6 @@ module Polyphony
160
160
  end
161
161
 
162
162
  # Resumes all waiting fibers.
163
- #
164
- # @return [void]
165
163
  def broadcast
166
164
  return if @queue.empty?
167
165
 
@@ -20,7 +20,7 @@ module Polyphony
20
20
 
21
21
  # Resets the default thread pool.
22
22
  #
23
- # @return [void]
23
+ # @return [nil]
24
24
  def self.reset
25
25
  return unless @default_pool
26
26
 
@@ -78,8 +78,6 @@ module Polyphony
78
78
  private
79
79
 
80
80
  # Runs a processing loop on a worker thread.
81
- #
82
- # @return [void]
83
81
  def thread_loop
84
82
  while true
85
83
  run_queued_task
@@ -87,8 +85,6 @@ module Polyphony
87
85
  end
88
86
 
89
87
  # Runs the first queued task in the task queue.
90
- #
91
- # @return [void]
92
88
  def run_queued_task
93
89
  (block, watcher) = @task_queue.shift
94
90
  result = block.()
@@ -28,7 +28,6 @@ module Polyphony
28
28
  # Sleeps for the given duration.
29
29
  #
30
30
  # @param duration [Number] sleep duration in seconds
31
- # @return [void]
32
31
  def sleep(duration)
33
32
  fiber = Fiber.current
34
33
  @timeouts[fiber] = {
@@ -56,7 +55,6 @@ module Polyphony
56
55
  # consecutive iterations.
57
56
  #
58
57
  # @param interval [Number] interval between consecutive iterations in seconds
59
- # @return [void]
60
58
  def every(interval)
61
59
  fiber = Fiber.current
62
60
  @timeouts[fiber] = {
@@ -180,8 +178,6 @@ module Polyphony
180
178
  end
181
179
 
182
180
  # Resets the timeout for the current fiber.
183
- #
184
- # @return [void]
185
181
  def reset
186
182
  record = @timeouts[Fiber.current]
187
183
  return unless record
@@ -216,8 +212,6 @@ module Polyphony
216
212
  end
217
213
 
218
214
  # Runs a timer iteration, invoking any timeouts that are due.
219
- #
220
- # @return [void]
221
215
  def update
222
216
  return if @timeouts.empty?
223
217
 
@@ -213,7 +213,6 @@ class ::Fiber
213
213
  # @option opts [Proc, nil] :on_done proc to call when a supervised fiber is terminated
214
214
  # @option opts [Proc, nil] :on_error proc to call when a supervised fiber is terminated with an exception
215
215
  # @option opts [:always, :on_error, nil] :restart whether to restart terminated fibers
216
- # @return [void]
217
216
  def supervise(*fibers, **opts, &block)
218
217
  block ||= supervise_opts_to_block(opts)
219
218
 
@@ -375,7 +374,7 @@ class ::Fiber
375
374
  # @param block [Proc] fiber's block
376
375
  # @param caller [Array<String>] fiber's caller
377
376
  # @param parent [Fiber] fiber's parent
378
- # @return [void]
377
+ # @return [Fiber] self
379
378
  def prepare(tag, block, caller, parent)
380
379
  @thread = Thread.current
381
380
  @tag = tag
@@ -384,12 +383,13 @@ class ::Fiber
384
383
  @block = block
385
384
  Thread.backend.trace(:spin, self, Kernel.caller[1..-1])
386
385
  schedule
386
+ self
387
387
  end
388
388
 
389
389
  # Runs the fiber's block and handles uncaught exceptions.
390
390
  #
391
391
  # @param first_value [any] value passed to fiber on first resume
392
- # @return [void]
392
+ # @return [any] fiber result
393
393
  def run(first_value)
394
394
  Kernel.raise first_value if first_value.is_a?(Exception)
395
395
  @running = true
@@ -397,6 +397,7 @@ class ::Fiber
397
397
  Thread.backend.trace(:unblock, self, first_value, @caller)
398
398
  result = @block.(first_value)
399
399
  finalize(result)
400
+ result
400
401
  rescue Polyphony::Restart => e
401
402
  restart_self(e.value)
402
403
  rescue Polyphony::MoveOn, Polyphony::Terminate => e
@@ -411,27 +412,29 @@ class ::Fiber
411
412
  # fiber terminates after it has already been created. Calling #setup_raw
412
413
  # allows the fiber to be scheduled and to receive messages.
413
414
  #
414
- # @return [void]
415
+ # @return [Fiber] self
415
416
  def setup_raw
416
417
  @thread = Thread.current
417
418
  @running = true
419
+ self
418
420
  end
419
421
 
420
422
  # Sets up the fiber as the main fiber for the current thread.
421
423
  #
422
- # @return [void]
424
+ # @return [Fiber] self
423
425
  def setup_main_fiber
424
426
  @main = true
425
427
  @tag = :main
426
428
  @thread = Thread.current
427
429
  @running = true
428
430
  @children&.clear
431
+ self
429
432
  end
430
433
 
431
434
  # Resets the fiber's state and reruns the fiber.
432
435
  #
433
436
  # @param first_value [Fiber] first_value to pass to fiber after restarting
434
- # @return [void]
437
+ # @return [any] fiber result
435
438
  def restart_self(first_value)
436
439
  @mailbox = nil
437
440
  run(first_value)
@@ -441,7 +444,7 @@ class ::Fiber
441
444
  #
442
445
  # @param result [any] return value
443
446
  # @param uncaught_exception [Exception, nil] uncaught exception
444
- # @return [void]
447
+ # @return [false]
445
448
  def finalize(result, uncaught_exception = false)
446
449
  result, uncaught_exception = finalize_children(result, uncaught_exception)
447
450
  Thread.backend.trace(:terminate, self, result)
@@ -462,7 +465,7 @@ class ::Fiber
462
465
  #
463
466
  # @param result [any] fiber's return value
464
467
  # @param uncaught_exception [Exception, nil] uncaught exception
465
- # @return [void]
468
+ # @return [Array] array containing result and uncaught exception if any
466
469
  def finalize_children(result, uncaught_exception)
467
470
  shutdown_all_children(graceful_shutdown?)
468
471
  [result, uncaught_exception]
@@ -474,7 +477,7 @@ class ::Fiber
474
477
  #
475
478
  # @param result [any] fiber's return value
476
479
  # @param uncaught_exception [Exception, nil] uncaught exception
477
- # @return [void]
480
+ # @return [Fiber] self
478
481
  def inform_monitors(result, uncaught_exception)
479
482
  if @monitors
480
483
  msg = [self, result]
@@ -485,6 +488,8 @@ class ::Fiber
485
488
  parent_is_monitor = @monitors&.has_key?(@parent)
486
489
  @parent.schedule_with_priority(result) unless parent_is_monitor
487
490
  end
491
+
492
+ self
488
493
  end
489
494
 
490
495
  # Adds a fiber to the list of monitoring fibers. Monitoring fibers will be
@@ -598,8 +603,6 @@ class ::Fiber
598
603
  # running, it will bubble up to the main thread's main fiber, which will
599
604
  # also be scheduled with priority. This method is mainly used trapping
600
605
  # signals (see also the patched `Kernel#trap`)
601
- #
602
- # @return [void]
603
606
  def schedule_priority_oob_fiber(&block)
604
607
  oob_fiber = Fiber.new do
605
608
  Fiber.current.setup_raw
@@ -355,7 +355,7 @@ class ::IO
355
355
  #
356
356
  # @param maxlen [Integer] maximum bytes to receive
357
357
  # @yield [String] read data
358
- # @return [void]
358
+ # @return [IO] self
359
359
  def read_loop(maxlen = 8192, &block)
360
360
  Polyphony.backend_read_loop(self, maxlen, &block)
361
361
  end
@@ -376,7 +376,7 @@ class ::IO
376
376
  #
377
377
  # @param receiver [any] receiver object
378
378
  # @param method [Symbol] method to call
379
- # @return [void]
379
+ # @return [IO] self
380
380
  def feed_loop(receiver, method = :call, &block)
381
381
  Polyphony.backend_feed_loop(self, receiver, method, &block)
382
382
  end