Coder Social home page Coder Social logo

it's Introduction

it

codecov CI

A collection of utilities for making working with iterables more bearable

Packages

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

it's People

Contributors

achingbrain avatar alanshaw avatar dependabot[bot] avatar evanhahn avatar gozala avatar hugomrdias avatar melusc avatar op avatar semantic-release-bot avatar wemeetagain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

it's Issues

Functions with union Promised return types "Promise<void> | void" will fail eslint checks.

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]

When publishing these packages, publish built / transpiled JavaScript

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!

it-latest: drop messages w/ backpressure

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).

browser-readablestream-to-it should release reader lock and cancel stream on break

Implementation here doesn't release reader lock

async function * browserReadableStreamToIt (stream) {
const reader = stream.getReader()
while (true) {
const result = await reader.read()
if (result.done) {
return
}
yield result.value
}
}

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. by breaking out of the loop.

By default, calling the async iterator’s return() method will also cancel the stream. To prevent this, use the stream’s values() method, passing true for the preventCancel option.

Would be nice to also have { preventCancel: true } option as in spec

TypeScript doesn't allow use with AsyncIterator<T>

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.