Skip to content

Commit

Permalink
docs: takeUntilStreamFactory 문서 작성 (#33)
Browse files Browse the repository at this point in the history
Merge pull request #33 from daengdaengLee/issue-32
  • Loading branch information
daengdaengLee authored Aug 17, 2023
2 parents 6d71403 + 3afb641 commit 2e278f5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Create a wrapped stream that yields data from the source stream while the predic
import { takeWhileStreamFactory } from "utilitystreams";

await pipeline(
takeWhilStreamFactory({ f: predicate }, readableStream),
takeWhileStreamFactory({ f: predicate }, readableStream),
// ... other streams
process.stdout,
);
Expand All @@ -238,11 +238,30 @@ await pipeline(
);
```

### takeUntilStreamFactory

Create a wrapped stream that yields data from the source stream until the predicate function returns true.

- support curry style
- `takeUntilStreamFactory({ f: predicate }, sourceStream)` -> `takeUntilStreamFactory({ f: predicate })(sourceStream)`
- source stream will be closed automatically when wrapped stream is closed.
- it returns async generator that is compatible with readable stream. If you want an exact stream, wrap it with `Readable.from`.

```typescript
import { takeUntilStreamFactory } from "utilitystreams";

await pipeline(
takeUntilStreamFactory({ f: predicate }, readableStream),
// ... other streams
process.stdout,
);
```

### TakeUntilStream

Take data until the predicate function returns true.
Yield data until the predicate function returns true.

- **If the source readable stream is large or infinite, you should prepare some end logic.**
- **If the source readable stream is large or infinite, you should prepare some end logic or use `takeUntilStreamFactory`. **
- It's very hard to "end" the stream "pipeline" in the middle.
- So, I prepare a callback function to do end the source readable stream.
- You have to prepare some error handling from destroy call or call some custom end logic.
Expand All @@ -253,11 +272,7 @@ import { TakeUntilStream } from "utilitystreams";
await pipeline(
readableStream,
// ... other streams
new TakeUntilStream({
f: (chunk) => {
return chunk.signal;
},
}),
new TakeUntilStream({ f: predicate }),
process.stdout,
);
```

0 comments on commit 2e278f5

Please sign in to comment.