Module: Async::Await::Enumerable

Defined in:
lib/async/await/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#async_each(parent: nil, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/async/await/enumerable.rb', line 23

def async_each(parent: nil, &block)
	Sync do |task|
		parent ||= task
		
		self.each do |*arguments|
			parent.async do
				yield(*arguments)
			end
		end
	end
	
	return self
end

#async_map(parent: nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/async/await/enumerable.rb', line 11

def async_map(parent: nil, &block)
	Sync do |task|
		parent ||= task
		
		self.map do |*arguments|
			parent.async do
				yield(*arguments)
			end
		end.map(&:wait)
	end
end