From 76553cf1c91fe8eae136493d5371101dcf9736aa Mon Sep 17 00:00:00 2001 From: AllanFly120 Date: Mon, 2 Mar 2020 08:56:29 -0800 Subject: [PATCH] fix: return readable stream with async iterators properly (#956) --- .../eventstream-serde-node/src/EventStreamMarshaller.ts | 8 ++++++-- packages/eventstream-serde-node/src/utils.ts | 6 +----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/eventstream-serde-node/src/EventStreamMarshaller.ts b/packages/eventstream-serde-node/src/EventStreamMarshaller.ts index 747f843217fb..58de1b0b2d19 100644 --- a/packages/eventstream-serde-node/src/EventStreamMarshaller.ts +++ b/packages/eventstream-serde-node/src/EventStreamMarshaller.ts @@ -6,7 +6,7 @@ import { EventStreamMarshaller as IEventStreamMarshaller } from "@aws-sdk/types"; import { Readable, pipeline } from "stream"; -import { ReadabletoIterable } from "./utils"; +import { readabletoIterable } from "./utils"; import { EventMessageChunkerStream } from "./EventMessageChunkerStream"; import { MessageUnmarshallerStream } from "./MessageUnmarshallerStream"; import { EventDeserializerStream } from "./EventDeserializerStream"; @@ -44,7 +44,11 @@ export class EventStreamMarshaller { ); //should use stream[Symbol.asyncIterable] when the api is stable //reference: https://nodejs.org/docs/latest-v11.x/api/stream.html#stream_readable_symbol_asynciterator - return ReadabletoIterable(eventDeserializerStream); + if (typeof eventDeserializerStream[Symbol.asyncIterator] === "function") { + // use the experimental feature if available. + return eventDeserializerStream; + } + return readabletoIterable(eventDeserializerStream); } serialize( diff --git a/packages/eventstream-serde-node/src/utils.ts b/packages/eventstream-serde-node/src/utils.ts index b57be2125126..e092348eaeba 100644 --- a/packages/eventstream-serde-node/src/utils.ts +++ b/packages/eventstream-serde-node/src/utils.ts @@ -18,13 +18,9 @@ export function getSignatureBinary(signature: string): Uint8Array { * Reference: https://nodejs.org/docs/latest-v11.x/api/stream.html#stream_readable_symbol_asynciterator */ -export async function* ReadabletoIterable( +export async function* readabletoIterable( readStream: Readable ): AsyncIterable { - if (typeof readStream[Symbol.asyncIterator] === "function") { - // use the experimental feature if available. - throw readStream; - } let streamEnded = false; let generationEnded = false; const records = new Array();