Class: FiberStream::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/fiber_stream/pipeline.rb,
sig/fiber_stream.rbs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, sink) ⇒ Pipeline

Returns a new instance of Pipeline.



9
10
11
12
# File 'lib/fiber_stream/pipeline.rb', line 9

def initialize(source, sink)
  @source = source
  @sink = sink
end

Class Method Details

.build(source, sink) ⇒ Object

:nodoc:



5
6
7
# File 'lib/fiber_stream/pipeline.rb', line 5

def self.build(source, sink) # :nodoc:
  new(source, sink)
end

Instance Method Details

#runMat

Runs this pipeline in the current fiber.

This is equivalent to source.run_with(sink) for the source and sink definitions captured by Source#to. Repeated runs create new materializations, subject to the replayability and resource ownership semantics of the captured endpoints.

Returns:

  • (Mat)


20
21
22
# File 'lib/fiber_stream/pipeline.rb', line 20

def run
  @source.run_with(@sink)
end

#run_asyncRunningPipeline[Mat]

Runs this pipeline in a scheduler-backed background fiber.

The method starts one new materialization and returns a RunningPipeline handle that can wait for the materialized value, observe completion, and request cancellation. Starting background execution requires an installed Fiber.scheduler from a non-blocking current fiber. FiberStream does not depend on Async at runtime.

Returns:



31
32
33
34
35
# File 'lib/fiber_stream/pipeline.rb', line 31

def run_async
  validate_scheduler!

  RunningPipeline.start(Fiber.scheduler) { run }
end