# subscribe

```ts
function subscribe<T, R>(iter: AsyncIterator<T, R>): Subscription<T, R>
```

Convert any [`AsyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator) into an effection [Subscription](https://frontside.com/effection/api/v4-next/Subscription.md)

This allows you to consume any `AsyncIterator` as a [Subscription](https://frontside.com/effection/api/v4-next/Subscription.md).

### Examples
#### Example 1
```ts
import { subscribe } from "effection";

let response = await fetch("https://example.com/data.bin");
let iterator = response.body?.[Symbol.asyncIterator]();

if (!iterator) throw new Error("response has no body");

let subscription = subscribe(iterator);
let first = yield* subscription.next();
if (!first.done) {
  console.log(first.value); // Uint8Array chunk
}
```

---
### Type Parameters
T


R


### Parameters


**iter**: AsyncIterator&lt;T, R&gt;


the iterator to convert
### Return Type


[Subscription](https://frontside.com/effection/api/v4-next/Subscription.md)&lt;T, R&gt;


a subscription that will produce each item of `iter`

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/async.ts#L30)
