module Fiber::Annotation

def annotate(annotation)

@returns [Object] The return value of the block.
@yields {} The block to execute with the given annotation.
@parameter annotation [Object] The annotation to set.

The block form of this method should only be invoked on the current fiber.

If a block is given, the annotation is set for the duration of the block and then restored to the previous value.

Annotate the current fiber with the given annotation.
def annotate(annotation)
	if block_given?
		raise "Cannot annotation a different fiber!" unless Fiber.current == self
		
		begin
			current_annotation = @annotation
			@annotation = annotation
			return yield
		ensure
			@annotation = current_annotation
		end
	else
		@annotation = annotation
	end
end

def initialize(annotation: nil, **options, &block)

@parameter annotation [Object] The annotation to set.
Annotate the current fiber with the given annotation.
def initialize(annotation: nil, **options, &block)
	@annotation = annotation
	super(**options, &block)
end