-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
4bc229e
to
1b32eb5
Compare
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.
1b32eb5
to
a2f437f
Compare
createConcatStream([]) | ||
]); | ||
|
||
expect(output).to.eql([1,2,3]); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numbers?
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this important?
There was a problem hiding this comment.
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')]); |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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>} |
There was a problem hiding this comment.
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"
src/utils/streams/list_stream.js
Outdated
* @param {Array<any>} items - the list of items to provide | ||
* @return {Readable} | ||
*/ | ||
export function createListStream(items) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
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
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
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