-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New factory API in object-oriented style * Pipe util, interval source, string stream and tests Extract pipe function into util/pipe Fix string stream More tests Add Interval source * map() conformance; first() and last() API changes Fix map() to conform to AsyncIteratorHelp proposal Make predicate optional in first() and last() * Rename AsyncStream -> AsyncIterableStream * Rename polyfill method asyncStream -> streamAsync * Moved stream sources to source/ * Decouple sources from AsyncIteratorStream * Clean up polyfills * Polyfills are actually factories * Add Scheduler abstraction to interval source * Core-js, range tests, sources naming convention * Polyfill Iterator Helpers for test if necessary * Rename source to sources * Fix editor tab size for vscode * Add Event source * Fix pipe.close() to notify waiting next()s * Readable release on iterator end and back-pressure * Rename readable APIs * Rename readable files * AsyncStream -> AsyncIterableStream in comments and related identifiers * AsyncIterableStream -> AsyncIteratorStream * ReadableSplit error handling * Make readableSplit and fromEvent lazy (like rxjs) * Readable.chunks * Use Genearator types and start/next/stop pattern * AsyncGenerator factory from {next, start, stop} functions * readableLines2 - simpler implementation * Introducing IteratorStream * Add sync IteratorHelper protocol * Move test_cli.ts from src/ to new demos/ folder (not packaged) * Bug fixes, improvements, reorg * Hyphenated folder names et al * Fix comment in unit test
- Loading branch information
1 parent
753fd38
commit 53be8ed
Showing
54 changed files
with
2,184 additions
and
1,085 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "test_cli", | ||
"skipFiles": ["<node_internals>/**"], | ||
"program": "${workspaceFolder}/test_cli.js", | ||
"preLaunchTask": "tsc: build - tsconfig.json", | ||
"outFiles": ["${workspaceFolder}/./**/*.js"] | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach by Process ID", | ||
"processId": "${command:PickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import "../factories/index.js"; | ||
|
||
console.log("Start", process.stdin.readableFlowing); | ||
|
||
process.stdin | ||
.lines() | ||
.stream() | ||
.take(2) | ||
.map((s) => s.substring(0, 2).toLocaleLowerCase()) | ||
.forEach((s) => console.log(s, process.stdin.readableFlowing)) | ||
.then(() => { | ||
console.log("- stdin is", process.stdin.readableFlowing); | ||
process.stdin | ||
.lines() | ||
.stream() | ||
.take(1) | ||
.map((s) => s.toUpperCase()) | ||
.forEach((s) => console.log(s, process.stdin.readableFlowing)) | ||
.then(() => console.log("End", process.stdin.readableFlowing)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import "./factories"; | ||
import { iteratorInterval } from "./sources/interval"; | ||
import { logger } from "./behavior.test"; | ||
|
||
test("some() consumes iterator", async () => { | ||
// See https://github.com/tc39/proposal-iterator-helpers?tab=readme-ov-file#somefn | ||
async function* naturals() { | ||
let i = 0; | ||
while (true) { | ||
yield i; | ||
i += 1; | ||
} | ||
} | ||
|
||
const iter = naturals().stream().take(4); | ||
|
||
const result1 = await iter.some((v) => v > 1); // true | ||
const result2 = await iter.some((_) => true); // false, iterator is already consumed. | ||
|
||
expect(result1).toBe(true); | ||
expect(result2).toBe(false); | ||
}); | ||
|
||
test("map() concurrent helpers - results are computed concurrently", async () => { | ||
// See https://github.com/tc39/proposal-async-iterator-helpers?tab=readme-ov-file#concurrency | ||
const log = logger(); | ||
const gen = [50, 10] | ||
.values() | ||
.streamAsync() | ||
.map((n) => | ||
iteratorInterval(n) | ||
.stream() | ||
.map((_) => n) | ||
.peek((v) => log(v)) | ||
.first(), | ||
); | ||
|
||
const result = (await Promise.all([gen.next(), gen.next()])).map( | ||
(x) => x.value, | ||
); | ||
|
||
expect(result).toEqual([50, 10]); | ||
expect(log.output).toEqual([10, 50]); | ||
}); |
Oops, something went wrong.