-
Notifications
You must be signed in to change notification settings - Fork 349
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: add option to use async iterables #605
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note: I avoided using
=>
|
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jun 30, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
paralin
added a commit
to aperturerobotics/starpc
that referenced
this pull request
Jul 1, 2022
Remove Observable<T> completely in favor of AsyncIterable<T>. Uses the useAsyncIterable flag in ts-proto. stephenh/ts-proto#605 Signed-off-by: Christian Stewart <christian@paral.in>
@stephenh Tested this & released for starpc, converted everything to AsyncIterable from Observable: aperturerobotics/starpc@4ecfbe9 |
Adds option useAsyncIterable which uses AsyncIterable instead of Observable. For example: bidirectionalStreamingRequest( service: string, method: string, data: AsyncIterable<Uint8Array> ): AsyncIterable<Uint8Array> Generates Transform async iterables for encoding and decoding: // encodeTransform encodes a source of message objects. // Transform<TestMessage, Uint8Array> async *encodeTransform( source: AsyncIterable<TestMessage | TestMessage[]> | Iterable<TestMessage | TestMessage[]> ): AsyncIterable<Uint8Array> { for await (const pkt of source) { if (Array.isArray(pkt)) { for (const p of pkt) { yield* [TestMessage.encode(p).finish()]; } } else { yield* [TestMessage.encode(pkt).finish()]; } } }, // decodeTransform decodes a source of encoded messages. // Transform<Uint8Array, TestMessage> async *decodeTransform( source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]> ): AsyncIterable<TestMessage> { for await (const pkt of source) { if (Array.isArray(pkt)) { for (const p of pkt) { yield* [TestMessage.decode(p)]; } } else { yield* [TestMessage.decode(pkt)]; } } }, Generates RPC service implementations which use the Transform iterators: BidiStreaming(request: AsyncIterable<TestMessage>): AsyncIterable<TestMessage> { const data = TestMessage.encodeTransform(request); const result = this.rpc.bidirectionalStreamingRequest('simple.Test', 'BidiStreaming', data); return TestMessage.decodeTransform(result); } AsyncIterables indicate a stream has ended by closing with an optional error. Fixes stephenh#600 Signed-off-by: Christian Stewart <christian@paral.in>
Looks great, thanks! |
🎉 This PR is included in version 1.116.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Awesome, thanks @stephenh ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds option
useAsyncIterable
which usesAsyncIterable
instead ofObservable
.For example:
Generates
Transform
async iterables for encoding and decoding:Generates RPC service implementations which use the Transform iterators:
AsyncIterable
s indicate a stream has ended by closing with an optional error.