# Class LittleGhost::Support::InterruptibleStream

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Support/InterruptibleStream.html

InterruptibleStream turns a blocking producer into a lazy, cancellable Ruby
stream. It is useful when an SDK owns the blocking read but the agent still
needs deadlines and cooperative cancellation.

The producer receives an emitter callable. Ending enumeration early stops and
joins the producer; CleanupError is raised if it cannot be stopped within the
fixed shutdown bound. The producer remains on a worker thread even when the
consumer uses a Fiber scheduler, allowing cleanup to interrupt a provider SDK
or socket read that remains blocked.

    stream = LittleGhost::Support::InterruptibleStream.new(
      cancellation_token: token
    ) { |emit| source.each { |value| emit.call(value) } }

## Inheritance

`LittleGhost::Support::InterruptibleStream < Object`

## Includes

- `Enumerable`

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(cancellation_token:, deadline: nil, buffer_size: BUFFER_SIZE, &producer)
```

Configures a lazy stream. The producer starts when #each is consumed.

## Instance methods

<a id="method-i-each"></a>
### `#each`

```ruby
#each()
```

Yields produced values, raising producer, cancellation, deadline, or cleanup
errors in the caller.
