Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b5b88bd

Browse files
committed
Concurrent uploading in mirror services
perform_across_services is now called perform_async_across_services and accepts block which is runs async for given service
1 parent d48d718 commit b5b88bd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/active_storage/service/mirror_service.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ def initialize(primary:, mirrors:)
1818
end
1919

2020
def upload(key, io, checksum: nil)
21-
each_service.collect do |service|
22-
service.upload key, io.tap(&:rewind), checksum: checksum
21+
perform_async_across_services do |service|
22+
service.upload key, StringIO.new(io.tap(&:rewind).read), checksum: checksum
2323
end
2424
end
2525

2626
def delete(key)
27-
perform_across_services :delete, key
27+
perform_async_across_services { |service| service.delete key }
2828
end
2929

3030
private
3131
def each_service(&block)
3232
[ primary, *mirrors ].each(&block)
3333
end
3434

35-
def perform_across_services(method, *args)
36-
promises = services.collect do |service|
37-
Concurrent::Promise.execute { service.public_send method, *args }
35+
def perform_async_across_services(&block)
36+
promises = each_service.collect do |service|
37+
Concurrent::Promise.execute { yield service }
3838
end
39-
Concurrent::Promise.zip(*promises).value
39+
Concurrent::Promise.zip(*promises).value!
4040
end
4141
end

0 commit comments

Comments
 (0)