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

feat(async): add async/tee #919

Merged
merged 1 commit into from
May 18, 2021
Merged

feat(async): add async/tee #919

merged 1 commit into from
May 18, 2021

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented May 16, 2021

This PR adds the utility (tee) for branching the given async iterable into n copies.

This has been originally developed in https://github.com/kt3k/tee_async_iterable as part of file stream processing tool (which is not published yet).

@kt3k kt3k requested a review from ry May 16, 2021 13:42
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kt3k kt3k merged commit 5c0a0df into denoland:main May 18, 2021
@kt3k kt3k deleted the feat/async-tee branch May 18, 2021 13:39
@exe-dealer
Copy link
Contributor

exe-dealer commented Sep 2, 2021

This code is very fragile and buggy to be in std. It violates async iterator protocol

.next method should be able to queue concurent calls

import { tee } from 'https://deno.land/[email protected]/async/tee.ts';

async function * gen() {
  yield 1;
  yield 2;
}

const [left, right] = tee(gen());

// sequential calls works fine
console.log([await right.next(), await right.next()]);
// [ { value: 1, done: false }, { value: 2, done: false } ]

// should be able to enqueue concurent .next calls
console.log(await Promise.all([ left.next(), left.next() ]));
// [ { value: 1, done: false }, { value: 1, done: false } ]
// but it returns the same result twice

guys are you serious?

https://github.com/denoland/deno_std/blob/f519c159f23a3b2b2b14aa205c7d1af9ae0aacca/async/tee.ts#L98-L100

.return() should be called on source iterator to terminate iteration when all brunches are .return()'ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants