---
title: ExecStream
description: "A JS async iterator over an exec's output."
---

A JS async iterator over an exec's output.

Loop over the stream itself: `for await (const event of handle.stream())`. The object
`[Symbol.asyncIterator]()` returns has `next`, `return` and `throw` and no
`[Symbol.asyncIterator]()` of its own, though its generated type, `__NapiRsAsyncGenerator`,
declares one. So `for await` over that object type-checks, then throws a `TypeError`
because it isn't async iterable (#262).

See the module docs for why this is a task and a bounded channel. The receiver is behind
a tokio `Mutex` because `AsyncGenerator::next` must answer a `Send + 'static` future, so
the guard is taken *inside* that future rather than borrowed from `&mut self`.

This type implements JavaScript's async iterable protocol.
It can be used with `for await...of` loops.

## See

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration\_protocols#the\_async\_iterator\_and\_async\_iterable\_protocols

## Methods

### \[Symbol.asyncIterator]\()

```ts
[Symbol.asyncIterator](): __NapiRsAsyncGenerator<ExecStream, StreamEvent, void, undefined>;
```

#### Returns

`__NapiRsAsyncGenerator`\<`ExecStream`, [`StreamEvent`](/microvms-agentd/reference/typescript/interfaces/streamevent/), `void`, `undefined`>

## Provenance

This page is generated from `bindings/microvms-js/index.d.ts` by TypeDoc 0.28.20 and typedoc-plugin-markdown 4.13.1, run from `site/scripts/gen-reference.mjs` on every `pnpm run sync`, so an edit made here is overwritten by the next run.

To change the page, change the doc comment in the binding's Rust source, then regenerate the declarations with `mise run dts`. `mise run dts:check` fails when the committed file no longer matches the source.