Skip to content

Commit f93fa7f

Browse files
author
Thomas Grainger
committed
generate stream without promise
streams are already async, and don't need to be wrapped in a promise.
1 parent 4a4f21c commit f93fa7f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { launch, LaunchedChrome } from 'chrome-launcher';
44
import * as CDP from 'chrome-remote-interface';
5+
import { Readable, Stream } from 'stream';
56

67
import { ChromePrintOptions } from './ChromePrintOptions';
78
import * as CompletionTrigger from './CompletionTrigger';
@@ -86,6 +87,20 @@ async function generate(html: string, options: CreateOptions): Promise<CreateRes
8687
}
8788
}
8889

90+
function generateToStream(html: string, options: CreateOptions): Stream {
91+
const stream = new Readable();
92+
(async () => {
93+
try {
94+
const result = await generate(html, options);
95+
stream.push(result.toBase64(), 'base64');
96+
stream.push(null);
97+
} catch (e) {
98+
stream.emit('error', e);
99+
}
100+
})();
101+
return stream;
102+
}
103+
89104
/**
90105
* Throws an exception if the operation has been canceled.
91106
*

0 commit comments

Comments
 (0)