Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup the rosetta stone. #861

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions www/docs/async-rosetta-stone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,14 @@ Use an `AsyncIterable` to create an `AsyncIterator`:
let iterator = asyncIterable[Symbol.asyncIterator]();
```

Use a `Stream` as an operation to create a `Subscription`:
Use a `Stream` to create a `Subscription`:

```js
let subscription = yield* stream;
```

To convert an `AsyncIterable` to a `Stream` use [`stream()`][stream]
To convert an `AsyncIterable` to a `Stream` use the [`stream()`][stream]
function.

```js
import { stream } from 'effection';
Expand All @@ -206,7 +207,38 @@ let itemStream = stream(asyncIterable);

A stateful sequence of items that can be evaluated one at a time.

Access the next item in an async iterator:

```js
let next = await iterator.next();
if (next.done) {
return next.value;
} else {
console.log(next.value)
}
```

Access the next item in a subscription:

```js
let next = yield* subscription.next();
if (next.done) {
return next.value;
} else {
console.log(next.value);
}
```

To convert an `AsyncIterator` to a `Subscription`, use the
[`subscribe()`][subscribe] function.

```js
let subscription = subscribe(asyncIterator);
```

[call]: https://deno.land/x/effection/mod.ts?s=call
[run]: https://deno.land/x/effection/mod.ts?s=run
[scope-run]: https://deno.land/x/effection/mod.ts?s=Scope#method_run_0
[each]: https://deno.land/x/effection/mod.ts?s=each
[stream]: https://deno.land/x/effection/mod.ts?s=stream
[subscribe]: https://deno.land/x/effection/mod.ts?s=subscribe
Loading