Module: Kernel

Defined in:
lib/kernel/sync.rb,
lib/kernel/async.rb

Instance Method Summary collapse

Instance Method Details

#Async(*args, &block) ⇒ Object

Run the given block of code in a task, asynchronously, creating a reactor if necessary.



25
26
27
# File 'lib/kernel/async.rb', line 25

def Async(*args, &block)
	::Async::Reactor.run(*args, &block)
end

#Sync(&block) ⇒ Object

Run the given block of code synchronously, but within a reactor if not already in one.



25
26
27
28
29
30
31
# File 'lib/kernel/sync.rb', line 25

def Sync(&block)
	if task = ::Async::Task.current?
		yield
	else
		::Async::Reactor.run(&block).wait
	end
end