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

Side by Side Diff: sdk/lib/_internal/pub/asset/dart/serialize/transformer.dart

Issue 243793005: Don't require Transformer methods to return Futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 8 months 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.asset.serialize.transformer; 5 library pub.asset.serialize.transformer;
6 6
7 import 'dart:async';
7 import 'dart:isolate'; 8 import 'dart:isolate';
8 9
9 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
10 11
11 import '../serialize.dart'; 12 import '../serialize.dart';
13 import '../utils.dart';
12 import 'transform.dart'; 14 import 'transform.dart';
13 15
14 /// Converts [transformer] into a serializable map. 16 /// Converts [transformer] into a serializable map.
15 Map _serializeTransformer(Transformer transformer) { 17 Map _serializeTransformer(Transformer transformer) {
16 var port = new ReceivePort(); 18 var port = new ReceivePort();
17 port.listen((wrappedMessage) { 19 port.listen((wrappedMessage) {
18 respond(wrappedMessage, (message) { 20 respond(wrappedMessage, (message) {
19 if (message['type'] == 'isPrimary') { 21 if (message['type'] == 'isPrimary') {
20 return transformer.isPrimary(deserializeId(message['id'])); 22 return transformer.isPrimary(deserializeId(message['id']));
21 } else if (message['type'] == 'declareOutputs') { 23 } else if (message['type'] == 'declareOutputs') {
22 return (transformer as DeclaringTransformer).declareOutputs( 24 return new Future.sync(() {
23 new ForeignDeclaringTransform(message['transform'])) 25 return (transformer as DeclaringTransformer).declareOutputs(
24 .then((_) => null); 26 new ForeignDeclaringTransform(message['transform']));
27 }).then((_) => null);
25 } else { 28 } else {
26 assert(message['type'] == 'apply'); 29 assert(message['type'] == 'apply');
27 30
28 // Make sure we return null so that if the transformer's [apply] returns 31 // Make sure we return null so that if the transformer's [apply] returns
29 // a non-serializable value it doesn't cause problems. 32 // a non-serializable value it doesn't cause problems.
30 return transformer.apply( 33 return new Future.sync(() {
31 new ForeignTransform(message['transform'])).then((_) => null); 34 return transformer.apply(new ForeignTransform(message['transform']));
35 }).then((_) => null);
32 } 36 }
33 }); 37 });
34 }); 38 });
35 39
36 var type; 40 var type;
37 if (transformer is LazyTransformer) { 41 if (transformer is LazyTransformer) {
38 type = 'LazyTransformer'; 42 type = 'LazyTransformer';
39 } else if (transformer is DeclaringTransformer) { 43 } else if (transformer is DeclaringTransformer) {
40 type = 'DeclaringTransformer'; 44 type = 'DeclaringTransformer';
41 } else { 45 } else {
(...skipping 20 matching lines...) Expand all
62 66
63 /// Converts [transformerOrGroup] into a serializable map. 67 /// Converts [transformerOrGroup] into a serializable map.
64 Map serializeTransformerOrGroup(transformerOrGroup) { 68 Map serializeTransformerOrGroup(transformerOrGroup) {
65 if (transformerOrGroup is Transformer) { 69 if (transformerOrGroup is Transformer) {
66 return _serializeTransformer(transformerOrGroup); 70 return _serializeTransformer(transformerOrGroup);
67 } else { 71 } else {
68 assert(transformerOrGroup is TransformerGroup); 72 assert(transformerOrGroup is TransformerGroup);
69 return _serializeTransformerGroup(transformerOrGroup); 73 return _serializeTransformerGroup(transformerOrGroup);
70 } 74 }
71 } 75 }
OLDNEW
« no previous file with comments | « pkg/barback/test/utils.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698