Skip to content

Commit ef570a7

Browse files
committed
Move files where they belong
1 parent 292cc93 commit ef570a7

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

lib/concurrent.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
require 'concurrent/settable_struct'
3030
require 'concurrent/timer_task'
3131
require 'concurrent/tvar'
32-
require 'concurrent/lock_free_stack'
3332

3433
require 'concurrent/thread_safe/synchronized_delegator'
3534
require 'concurrent/thread_safe/util'

spec/concurrent/promises_spec.rb renamed to spec/concurrent/edge/promises_spec.rb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def behaves_as_delay(delay, value)
361361
branch1.zip(branch2).then { |b1, b2| b1 + b2 },
362362
(branch1 & branch2).then { |b1, b2| b1 + b2 }]
363363

364-
sleep 0.1
364+
Thread.pass until branch1.resolved?
365365
expect(branch1).to be_resolved
366366
expect(branch2).not_to be_resolved
367367

@@ -496,7 +496,7 @@ def behaves_as_delay(delay, value)
496496

497497
describe 'Throttling' do
498498
specify do
499-
max_tree = Concurrent::Throttle.new 3
499+
max_tree = Concurrent::Promises::Throttle.new 3
500500
counter = Concurrent::AtomicFixnum.new
501501
testing = -> *args do
502502
counter.increment
@@ -508,14 +508,43 @@ def behaves_as_delay(delay, value)
508508
expect(Concurrent::Promises.zip(
509509
*12.times.map do |i|
510510
max_tree.limit { |trigger| trigger.then &testing }
511-
end).value.all? { |v| v < 3 }).to be_truthy
511+
end).value!.all? { |v| v < 3 }).to be_truthy
512512

513513
expect(Concurrent::Promises.zip(
514514
*12.times.map do |i|
515515
Concurrent::Promises.
516516
fulfilled_future(i).
517517
throttle(max_tree) { |trigger| trigger.then &testing }
518-
end).value.all? { |v| v < 3 }).to be_truthy
518+
end).value!.all? { |v| v < 3 }).to be_truthy
519+
end
520+
521+
specify do
522+
max_five = Concurrent::Promises::Throttle.new 5
523+
jobs = 20.times.map do |i|
524+
max_five.limit do |trigger|
525+
# trigger is an event, has same chain-able capabilities as current promise
526+
trigger.then do
527+
# at any given time there max 5 simultaneous executions of this block
528+
the_work = i * 2
529+
end
530+
end
531+
end
532+
result = Concurrent::Promises.zip_futures(*jobs)
533+
p result.value!
534+
# => [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]
535+
end
536+
537+
specify do
538+
max_five = Concurrent::Promises::Throttle.new 5
539+
jobs = 20.times.map do |i|
540+
max_five.then_limit do
541+
# at any given time there max 5 simultaneous executions of this block
542+
the_work = i * 2
543+
end # returns promise
544+
end
545+
result = Concurrent::Promises.zip_futures(*jobs)
546+
p result.value!
547+
# => [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]
519548
end
520549
end
521550
end

0 commit comments

Comments
 (0)