6
6
7
7
# @note different name just not to collide for now
8
8
module Concurrent
9
+
10
+ # Provides edge features, which will be added to or replace features in main gem.
11
+ #
12
+ # Contains new unified implementation of Futures and Promises which combines Features of previous `Future`,
13
+ # `Promise`, `IVar`, `Probe`, `dataflow`, `Delay`, `TimerTask` into single framework. It uses extensively
14
+ # new synchronization layer to make all the paths lock-free with exception of blocking threads on `#wait`.
15
+ # It offers better performance and does not block threads (exception being #wait and similar methods where it's
16
+ # intended).
17
+ #
18
+ # ## Examples
19
+ # {include:file:examples/edge_futures.out.rb}.
9
20
module Edge
10
21
11
22
module FutureShortcuts
@@ -116,6 +127,7 @@ def wait(timeout = nil)
116
127
self
117
128
end
118
129
130
+ # @!visibility private
119
131
def touch
120
132
# distribute touch to promise only once
121
133
@Promise . touch if @Touched . make_true
@@ -172,7 +184,7 @@ def inspect
172
184
"#{ to_s [ 0 ..-2 ] } blocks:[#{ blocks . map ( &:to_s ) . join ( ', ' ) } ]>"
173
185
end
174
186
175
- # @api private
187
+ # @!visibility private
176
188
def complete ( raise = true )
177
189
if complete_state
178
190
# go to synchronized block only if there were waiting threads
@@ -185,7 +197,7 @@ def complete(raise = true)
185
197
self
186
198
end
187
199
188
- # @api private
200
+ # @!visibility private
189
201
# just for inspection
190
202
# @return [Array<AbstractPromise>]
191
203
def blocks
@@ -194,13 +206,13 @@ def blocks
194
206
end
195
207
end
196
208
197
- # @api private
209
+ # @!visibility private
198
210
# just for inspection
199
211
def callbacks
200
212
@Callbacks . each . to_a
201
213
end
202
214
203
- # @api private
215
+ # @!visibility private
204
216
def add_callback ( method , *args )
205
217
if completed?
206
218
call_callback method , *args
@@ -211,12 +223,14 @@ def add_callback(method, *args)
211
223
self
212
224
end
213
225
214
- # @api private, only for inspection
226
+ # @!visibility private
227
+ # only for inspection
215
228
def promise
216
229
@Promise
217
230
end
218
231
219
- # @api private, only for inspection
232
+ # @!visibility private
233
+ # only for inspection
220
234
def touched
221
235
@Touched . value
222
236
end
@@ -407,12 +421,12 @@ def on_failure!(&callback)
407
421
add_callback :pr_callback_on_failure , callback
408
422
end
409
423
410
- # @api private
424
+ # @!visibility private
411
425
def apply_value ( value , block )
412
426
block . call value
413
427
end
414
428
415
- # @api private
429
+ # @!visibility private
416
430
def complete ( success , value , reason , raise = true )
417
431
if complete_state success , value , reason
418
432
@Waiters . clear
@@ -499,15 +513,13 @@ def pr_async_callback_on_completion(success, value, reason, executor, callback)
499
513
500
514
class CompletableEvent < Event
501
515
# Complete the event
502
- # @api public
503
516
def complete ( raise = true )
504
517
super raise
505
518
end
506
519
end
507
520
508
521
class CompletableFuture < Future
509
522
# Complete the future
510
- # @api public
511
523
def complete ( success , value , reason , raise = true )
512
524
super success , value , reason , raise
513
525
end
0 commit comments