# Generator

`import { Generator } from "destack:async";`

Generator object.

A generator body runs on its own fiber; each step wakes the body with the
consumer request and blocks the consumer until the body yields or returns.

```ds title="Generator"
export class Generator<Y, R = void, N = void> {
    next(value: N | undefined): GeneratorResult<Y, R>;
    return(value: R): GeneratorResult<Y, R>;
}
```

[language/library/src/async/generator.ds:17:43](https://github.com/destack-sh/destack/blob/main/language/library/src/async/generator.ds#L17-L43)

## Members

### `next(value: N | undefined): GeneratorResult<Y, R>`

Advance the generator with one value.

### `return(value: R): GeneratorResult<Y, R>`

Finalize the generator and return the completion value.
