| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library barback.serialize; | 5 library barback.serialize; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 | 9 |
| 10 import 'package:stack_trace/stack_trace.dart'; | 10 import 'package:stack_trace/stack_trace.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 /// Convert a [SendPort] whose opposite is waiting to send us a stream into a | 39 /// Convert a [SendPort] whose opposite is waiting to send us a stream into a |
| 40 /// [Stream]. | 40 /// [Stream]. |
| 41 /// | 41 /// |
| 42 /// No stream data will actually be sent across the isolate boundary until | 42 /// No stream data will actually be sent across the isolate boundary until |
| 43 /// someone subscribes to the returned stream. | 43 /// someone subscribes to the returned stream. |
| 44 Stream deserializeStream(SendPort sendPort) { | 44 Stream deserializeStream(SendPort sendPort) { |
| 45 return callbackStream(() { | 45 return callbackStream(() { |
| 46 var receivePort = new ReceivePort(); | 46 var receivePort = new ReceivePort(); |
| 47 sendPort.send(receivePort.sendPort); | 47 sendPort.send(receivePort.sendPort); |
| 48 // TODO(nweiz): use a const constructor for StreamTransformer when issue | |
| 49 // 14971 is fixed. | |
| 50 return receivePort.transform( | 48 return receivePort.transform( |
| 51 new StreamTransformer(_deserializeTransformer)); | 49 const StreamTransformer(_deserializeTransformer)); |
| 52 }); | 50 }); |
| 53 } | 51 } |
| 54 | 52 |
| 55 /// The body of a [StreamTransformer] that deserializes the values in a stream | 53 /// The body of a [StreamTransformer] that deserializes the values in a stream |
| 56 /// sent by [serializeStream]. | 54 /// sent by [serializeStream]. |
| 57 StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { | 55 StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { |
| 58 var subscription; | 56 var subscription; |
| 59 var transformed = input.transform(new StreamTransformer.fromHandlers( | 57 var transformed = input.transform(new StreamTransformer.fromHandlers( |
| 60 handleData: (data, sink) { | 58 handleData: (data, sink) { |
| 61 if (data['type'] == 'data') { | 59 if (data['type'] == 'data') { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 /// A regular expression to match the exception prefix that some exceptions' | 115 /// A regular expression to match the exception prefix that some exceptions' |
| 118 /// [Object.toString] values contain. | 116 /// [Object.toString] values contain. |
| 119 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); | 117 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); |
| 120 | 118 |
| 121 /// Get a string description of an exception. | 119 /// Get a string description of an exception. |
| 122 /// | 120 /// |
| 123 /// Many exceptions include the exception class name at the beginning of their | 121 /// Many exceptions include the exception class name at the beginning of their |
| 124 /// [toString], so we remove that if it exists. | 122 /// [toString], so we remove that if it exists. |
| 125 String _getErrorMessage(error) => | 123 String _getErrorMessage(error) => |
| 126 error.toString().replaceFirst(_exceptionPrefix, ''); | 124 error.toString().replaceFirst(_exceptionPrefix, ''); |
| OLD | NEW |