Skip to content

Commit

Permalink
generate stream without promise
Browse files Browse the repository at this point in the history
streams are already async, and don't need to be wrapped in a promise.
  • Loading branch information
graingert committed Aug 23, 2017
1 parent 4a4f21c commit f93fa7f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

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

function generateToStream(html: string, options: CreateOptions): Stream {
const stream = new Readable();
(async () => {
try {
const result = await generate(html, options);
stream.push(result.toBase64(), 'base64');
stream.push(null);
} catch (e) {
stream.emit('error', e);
}
})();
return stream;
}

/**
* Throws an exception if the operation has been canceled.
*
Expand Down

0 comments on commit f93fa7f

Please sign in to comment.