achingbrain / it Goto Github PK
View Code? Open in Web Editor NEWA collection of utilities for making working with iterables more bearable
License: Other
A collection of utilities for making working with iterables more bearable
License: Other
Implementation here doesn't release reader lock
it/packages/browser-readablestream-to-it/index.js
Lines 3 to 15 in 1b928cb
According to the ReadableStreams specification 4.2.5. Asynchronous iteration
for await (const chunk of stream) { ... }
for await (const chunk of stream.values({ preventCancel: true })) { ... }
Asynchronously iterates over the chunks in the stream’s internal queue.
Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader. The lock will be released if the async iterator’s
return()
method is called, e.g. bybreak
ing out of the loop.By default, calling the async iterator’s
return()
method will also cancel the stream. To prevent this, use the stream’svalues()
method, passing true for thepreventCancel
option.
Would be nice to also have { preventCancel: true }
option as in spec
Cool project!
@achingbrain When publishing these packages to npm, etc., would you consider publishing built / transpiled JavaScript using a tool like rollup? Otherwise it makes it hard to use these libs in a project with a different Babel config.
This would mean adding a build script for each child package so that they're all run with the lerna command from the root dir.
Thanks!
This would be useful for rate limiting.
This would be a stage in a pipe() which keeps & emits the most recently received value (from another iterable) and drops messages during backpressure (keeping the latest message only).
Can you pls update formidable? Used in it-multipart at least.
https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md
When uploaded a file with diacritics, such as the aáa.txt
, a multipart iterator silently skips it.
it-take has a comment like this in its usage example:
// This can also be an iterator, async iterator, generator, etc
const arr = await all(take([0, 1, 2, 3, 4], 2))
So, I tried to use it with an async iterator. But the released packages include TypeScript definitions that look like this:
cd `mktemp -d`
npm pack it-take
tar zxf it-take-*.tgz
cat package/dist/index.d.ts
/**
* Stop iteration after n items have been received.
*
* @template T
* @param {AsyncIterable<T>|Iterable<T>} source
* @param {number} limit
* @returns {AsyncIterable<T>}
*/
declare function take<T>(source: AsyncIterable<T> | Iterable<T>, limit: number): AsyncIterable<T>;
Specifically, the source parameter is typed as AsyncIterable<T> | Iterable<T>
Unless I'm missing something, this does not seem to allow an AsyncIterator<T>
to be passed?AsyncIterator<T>
doesn't meet the type constraint, so trying to use it with an AsyncIterator<number>
results in:
error TS2345: Argument of type 'AsyncIterator<number, any, undefined>' is not assignable to parameter of type 'AsyncIterable | Iterable'.
Property '[Symbol.iterator]' is missing in type 'AsyncIterator<number, any, undefined>' but required in type 'Iterable'.
Two things indicate to me this is only a typing error, and can be fixed in just the TS definitions:
Converting the iterator to an actual iterable results in it working, e.g. using something like:
const toIterable = <T>(iterator: AsyncIterator<T>): AsyncIterable<T> => {
return {
[Symbol.asyncIterator]() {
return iterator
},
}
}
But, more importantly, type-casting the iterator to an iterable with no further changes also works as-is (i.e. take(asyncIteratorOfNumber as unknown as AsyncIterable<number>, 1)
works fine)
ESlint is not able to handle conditional returns like this in terms of awaiting.
Looks like folks over at typescript-eslint suggest to always mark functions that can return a promise with async, even if it returns immediately.
typescript-eslint/typescript-eslint#6421
Ran into this problem when awaiting drain
, eslint threw back this error in response.
Unexpected `await` of a non-Promise (non-"Thenable") value. [Error/@typescript-eslint/await-thenable]
Placing a void expression inside another expression is forbidden. Move it to its own statement instead. [Error/@typescript-eslint/no-confusing-void-expression]
It seems it-merge
still uses an old version of it-pushable
https://github.com/achingbrain/it/blob/master/packages/it-merge/package.json#L22
it-merge
is a dependency of it-pipe
(and likely others)
There are likely other packages here too that also need upgrading to push the upgraded it-*
dependencies through
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.