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

[utils/streams] implement some generic stream helpers #10187

Merged
merged 5 commits into from
Feb 11, 2017

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Feb 3, 2017

This is the first supporting pr of several that was pulled out of #9853 in an attempt to make it slightly more digestible.

While working on #9853 I have needed to deal with streams in several different ways and along the way ended up with a core set of stream helpers. Since these helpers are not browser or server specific, and are used across components, and tested with generic use in mind I put them in src/utils.

This PR does not include use of the helpers beyond the tests

@spalger spalger added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc review v5.3.0 v6.0.0 labels Feb 3, 2017
@spalger spalger requested a review from epixa February 3, 2017 22:16
@spalger spalger force-pushed the implement/stream-utils branch 6 times, most recently from 4bc229e to 1b32eb5 Compare February 3, 2017 23:34
@spalger spalger requested a review from kimjoar February 3, 2017 23:48
While working on pr 9853 I have needed to deal with streams in several different ways and along the way ended up with a core set of stream helpers. Since these helpers are not browser or server specific, and are used across components, and tested with generic use in mind I put them in src/utils.
@spalger spalger force-pushed the implement/stream-utils branch from 1b32eb5 to a2f437f Compare February 4, 2017 04:42
createConcatStream([])
]);

expect(output).to.eql([1,2,3]);
Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't really clear what the empty array input does on the concat. Maybe [0] or something, to make it clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe [0] or something, to make it clearer?

Not sure what you mean. You understand what it's doing though?

Copy link
Contributor

@kimjoar kimjoar Feb 8, 2017

Choose a reason for hiding this comment

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

I meant createConcatStream([0]) or something like that. Won't that end up as [0,1,2,3]? Might make the param a bit "clearer" in what role it has.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sounds good

expect(output).to.eql('abc');
});

it('works with strings', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arrays actually

).to.be('to be or not to be');
});

it('emits the intersperse value right before the second value, does not wait', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this important?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to ensure that this isn't holding onto chunks it doesn't need to. I'll pick a better title


describe('splitStream', () => {
it('splits buffers, produces strings', async () => {
const output = await split(createSplitStream('&'), [Buffer.from('foo&bar')]);
Copy link
Contributor

Choose a reason for hiding this comment

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

In other tests you use createPromiseFromStreams, should these also do that? (Or maybe good reason they're not?)

Copy link
Contributor Author

@spalger spalger Feb 8, 2017

Choose a reason for hiding this comment

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

Started using the createPromiseFromStreams helper in the split function above

@@ -0,0 +1,69 @@
import { race } from 'bluebird';
Copy link
Contributor

Choose a reason for hiding this comment

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

not used

* the promise to be rejected with that error.
*
* @param {Array<Stream>} streams
* @return {Promise<undefined>}
Copy link
Contributor

Choose a reason for hiding this comment

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

The undefined doesn't match the docs above: "will be provided as the promise value"

@epixa epixa removed the v5.3.0 label Feb 10, 2017
* @param {Array<any>} items - the list of items to provide
* @return {Readable}
*/
export function createListStream(items) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you didn't use a default argument here rather than the items || [] check on the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope

* writing/reading.
*
* If the last stream is readable, it's final value
* will be provided as the promise value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain the utility of this to me? I can't think of a practical scenario where the final value received in a stream should fulfill a promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used constantly in the tests with the concat stream, which always produces a single value. It's also the behavior of the Observable#toPromise() function in RxJS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, I agree that outside of tests and systems that use streams exclusively, for everything, this feature has limited value.

@epixa
Copy link
Contributor

epixa commented Feb 10, 2017

Since this is basically just some standalone utilities that aren't used yet, I can't really evaluate this in terms of whether this should even exist at all, but I trust you that this is necessary for the broader test framework changes. The code is in great shape, and the test coverage is there.

LGTM

@spalger spalger merged commit 3a272e8 into elastic:master Feb 11, 2017
@spalger spalger added the v5.4.0 label Feb 11, 2017
elastic-jasper added a commit that referenced this pull request Feb 11, 2017
Backports PR #10187

**Commit 1:**
[utils/streams] implement some generic stream helpers

While working on pr 9853 I have needed to deal with streams in several different ways and along the way ended up with a core set of stream helpers. Since these helpers are not browser or server specific, and are used across components, and tested with generic use in mind I put them in src/utils.

* Original sha: a2f437f
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-03T22:07:24Z

**Commit 2:**
Merge branch 'master' of github.com:elastic/kibana into implement/stream-utils

* Original sha: b638d21
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-08T19:17:01Z

**Commit 3:**
[utils/streams] address kim's feedback

* Original sha: 8566549
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-08T19:22:11Z

**Commit 4:**
Merge branch 'master' of github.com:elastic/kibana into implement/stream-utils

* Original sha: a93df5a
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-10T20:47:20Z

**Commit 5:**
[utils/stream/list] move default value into arg list

* Original sha: 747218e
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-10T20:54:42Z
epixa pushed a commit that referenced this pull request Feb 11, 2017
Backports PR #10187

**Commit 1:**
[utils/streams] implement some generic stream helpers

While working on pr 9853 I have needed to deal with streams in several different ways and along the way ended up with a core set of stream helpers. Since these helpers are not browser or server specific, and are used across components, and tested with generic use in mind I put them in src/utils.

* Original sha: a2f437f
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-03T22:07:24Z

**Commit 2:**
Merge branch 'master' of github.com:elastic/kibana into implement/stream-utils

* Original sha: b638d21
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-08T19:17:01Z

**Commit 3:**
[utils/streams] address kim's feedback

* Original sha: 8566549
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-08T19:22:11Z

**Commit 4:**
Merge branch 'master' of github.com:elastic/kibana into implement/stream-utils

* Original sha: a93df5a
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-10T20:47:20Z

**Commit 5:**
[utils/stream/list] move default value into arg list

* Original sha: 747218e
* Authored by spalger <spalger@users.noreply.github.com> on 2017-02-10T20:54:42Z
@spalger spalger deleted the implement/stream-utils branch October 18, 2019 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v5.4.0 v6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants