Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart

Issue 113453005: Add stack chain support to pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 pub.load_transformers; 5 library pub.load_transformers;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 // TODO(nweiz): don't import from "src" once issue 14966 is fixed. 12 // TODO(nweiz): don't import from "src" once issue 14966 is fixed.
13 import 'package:barback/src/internal_asset.dart'; 13 import 'package:barback/src/internal_asset.dart';
14 import 'package:source_maps/source_maps.dart'; 14 import 'package:source_maps/source_maps.dart';
15 import 'package:stack_trace/stack_trace.dart';
15 16
16 import '../barback.dart'; 17 import '../barback.dart';
17 import '../dart.dart' as dart; 18 import '../dart.dart' as dart;
18 import '../log.dart' as log; 19 import '../log.dart' as log;
19 import '../utils.dart'; 20 import '../utils.dart';
20 import 'server.dart'; 21 import 'server.dart';
21 22
22 /// A Dart script to run in an isolate. 23 /// A Dart script to run in an isolate.
23 /// 24 ///
24 /// This script serializes one or more transformers defined in a Dart library 25 /// This script serializes one or more transformers defined in a Dart library
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 Map _serializeId(AssetId id) => {'package': id.package, 'path': id.path}; 536 Map _serializeId(AssetId id) => {'package': id.package, 'path': id.path};
536 537
537 /// Responds to a message sent by [_call]. 538 /// Responds to a message sent by [_call].
538 /// 539 ///
539 /// [wrappedMessage] is the raw message sent by [_call]. This unwraps it and 540 /// [wrappedMessage] is the raw message sent by [_call]. This unwraps it and
540 /// passes the contents of the message to [callback], then sends the return 541 /// passes the contents of the message to [callback], then sends the return
541 /// value of [callback] back to [_call]. If [callback] returns a Future or 542 /// value of [callback] back to [_call]. If [callback] returns a Future or
542 /// throws an error, that will also be sent. 543 /// throws an error, that will also be sent.
543 void _respond(wrappedMessage, callback(message)) { 544 void _respond(wrappedMessage, callback(message)) {
544 var replyTo = wrappedMessage['replyTo']; 545 var replyTo = wrappedMessage['replyTo'];
545 new Future.sync(() => callback(wrappedMessage['message'])) 546 syncFuture(() => callback(wrappedMessage['message']))
546 .then((result) => replyTo.send({'type': 'success', 'value': result})) 547 .then((result) => replyTo.send({'type': 'success', 'value': result}))
547 .catchError((error, stackTrace) { 548 .catchError((error, stackTrace) {
548 // TODO(nweiz): at least MissingInputException should be preserved here. 549 // TODO(nweiz): at least MissingInputException should be preserved here.
549 replyTo.send({ 550 replyTo.send({
550 'type': 'error', 551 'type': 'error',
551 'error': dart.CrossIsolateException.serialize(error, stackTrace) 552 'error': dart.CrossIsolateException.serialize(error, stackTrace)
552 }); 553 });
553 }); 554 });
554 } 555 }
555 556
556 /// Wraps [message] and sends it across [port], then waits for a response which 557 /// Wraps [message] and sends it across [port], then waits for a response which
557 /// should be sent using [_respond]. 558 /// should be sent using [_respond].
558 /// 559 ///
559 /// The returned Future will complete to the value or error returned by 560 /// The returned Future will complete to the value or error returned by
560 /// [_respond]. 561 /// [_respond].
561 Future _call(SendPort port, message) { 562 Future _call(SendPort port, message) {
562 var receivePort = new ReceivePort(); 563 var receivePort = new ReceivePort();
563 port.send({ 564 port.send({
564 'message': message, 565 'message': message,
565 'replyTo': receivePort.sendPort 566 'replyTo': receivePort.sendPort
566 }); 567 });
567 568
568 return receivePort.first.then((response) { 569 return Chain.track(receivePort.first).then((response) {
569 if (response['type'] == 'success') return response['value']; 570 if (response['type'] == 'success') return response['value'];
570 assert(response['type'] == 'error'); 571 assert(response['type'] == 'error');
571 return new Future.error( 572 return new Future.error(
572 new dart.CrossIsolateException.deserialize(response['error'])); 573 new dart.CrossIsolateException.deserialize(response['error']),
574 new Chain.current());
573 }); 575 });
574 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698