Committed by
David PHAM-VAN
Save in an isolate when available
Showing
5 changed files
with
26 additions
and
7 deletions
| @@ -251,11 +251,13 @@ class PdfDocument { | @@ -251,11 +251,13 @@ class PdfDocument { | ||
| 251 | 251 | ||
| 252 | /// Generate the PDF document as a memory file | 252 | /// Generate the PDF document as a memory file |
| 253 | Future<Uint8List> save() async { | 253 | Future<Uint8List> save() async { |
| 254 | - final os = PdfStream(); | ||
| 255 | - if (prev != null) { | ||
| 256 | - os.putBytes(prev!.bytes); | ||
| 257 | - } | ||
| 258 | - await _write(os); | ||
| 259 | - return os.output(); | 254 | + return pdfCompute(() async { |
| 255 | + final os = PdfStream(); | ||
| 256 | + if (prev != null) { | ||
| 257 | + os.putBytes(prev!.bytes); | ||
| 258 | + } | ||
| 259 | + await _write(os); | ||
| 260 | + return os.output(); | ||
| 261 | + }); | ||
| 260 | } | 262 | } |
| 261 | } | 263 | } |
| @@ -20,3 +20,10 @@ import '../format/object_base.dart'; | @@ -20,3 +20,10 @@ import '../format/object_base.dart'; | ||
| 20 | 20 | ||
| 21 | /// Zip compression function | 21 | /// Zip compression function |
| 22 | DeflateCallback defaultDeflate = const ZLibEncoder().encode; | 22 | DeflateCallback defaultDeflate = const ZLibEncoder().encode; |
| 23 | + | ||
| 24 | +/// The dart:html implementation of [pdfCompute]. | ||
| 25 | +@pragma('dart2js:tryInline') | ||
| 26 | +Future<R> pdfCompute<R>(Future<R> Function() computation) async { | ||
| 27 | + await null; | ||
| 28 | + return computation(); | ||
| 29 | +} |
| @@ -15,8 +15,14 @@ | @@ -15,8 +15,14 @@ | ||
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | import 'dart:io'; | 17 | import 'dart:io'; |
| 18 | +import 'dart:isolate'; | ||
| 18 | 19 | ||
| 19 | import '../format/object_base.dart'; | 20 | import '../format/object_base.dart'; |
| 20 | 21 | ||
| 21 | /// Zip compression function | 22 | /// Zip compression function |
| 22 | DeflateCallback defaultDeflate = zlib.encode; | 23 | DeflateCallback defaultDeflate = zlib.encode; |
| 24 | + | ||
| 25 | +/// The dart:io implementation of [pdfCompute]. | ||
| 26 | +@pragma('vm:prefer-inline') | ||
| 27 | +Future<R> pdfCompute<R>(Future<R> Function() computation) async => | ||
| 28 | + Isolate.run<R>(computation, debugName: 'dart_pdf'); |
-
Please register or login to post a comment