module Kernel

def Barrier(parent: Async::Idler.new, **options)

@public Since *Async v2.34*.
@parameter **options [Hash] Additional options passed to {Kernel::Sync}.
@parameter parent [Task | Semaphore | Nil] The parent for holding any children tasks.

By default, the barrier uses an `Async::Idler` to manage load, but this can be overridden by providing a different parent or `nil` to disable load management.

If no scheduler is running, one will be created automatically for the duration of the block.

Create a barrier, yield it to the block, and then wait for all tasks to complete.
def Barrier(parent: Async::Idler.new, **options)
	Sync(**options) do |task|
		barrier = ::Async::Barrier.new(parent: parent)
		
		yield barrier
		
		barrier.wait
	ensure
		barrier&.stop
	end
end