Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
attach(
writer: NodeJS.WritableStream,
reader: NodeJS.ReadableStream,
client: any
) {
this.writer = writer;
this.reader = reader;
this.client = client;
this.reader.on('end', () => {
this.emit('detach');
});
const asyncDecodeGenerator = decodeStream(this.reader as any, {
extensionCodec: this.extensionCodec,
});
// naively iterate async generator created via decodeStream.
// when runtime / polyfill allows replace to `for await (const val of asyncDecodeGenerator)`
// syntax instead.
const resolveGeneratorRecursively = (iter: AsyncGenerator) => {
iter.next().then(resolved => {
if (!resolved.done) {
this.parseMessage(resolved.value);
return resolveGeneratorRecursively(iter);
}
return Promise.resolve();
});
};