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

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart

Issue 2653253002: Use microtasks in dart.async (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// This library adapts ES6 generators to implement Dart's async/await. 5 /// This library adapts ES6 generators to implement Dart's async/await.
6 /// It's designed to interact with Dart's Future/Stream and follow Dart 6 /// It's designed to interact with Dart's Future/Stream and follow Dart
7 /// async/await semantics. 7 /// async/await semantics.
8 /// See https://github.com/dart-lang/sdk/issues/27315 for ideas on 8 /// See https://github.com/dart-lang/sdk/issues/27315 for ideas on
9 /// reconciling Dart's Future and ES6 Promise. 9 /// reconciling Dart's Future and ES6 Promise.
10 /// Inspired by `co`: https://github.com/tj/co/blob/master/index.js, which is a 10 /// Inspired by `co`: https://github.com/tj/co/blob/master/index.js, which is a
(...skipping 24 matching lines...) Expand all
35 // 35 //
36 // In essence, we are giving the code inside the generator a chance to 36 // In essence, we are giving the code inside the generator a chance to
37 // use try-catch-finally. 37 // use try-catch-finally.
38 return next(iter.throw(err)); 38 return next(iter.throw(err));
39 } 39 }
40 function next(ret) { 40 function next(ret) {
41 if (ret.done) return ret.value; 41 if (ret.done) return ret.value;
42 // Checks if the awaited value is a Future. 42 // Checks if the awaited value is a Future.
43 let future = ret.value; 43 let future = ret.value;
44 if (!$instanceOf(future, ${getGenericClass(Future)})) { 44 if (!$instanceOf(future, ${getGenericClass(Future)})) {
45 future = $Future.value(future); 45 var result = future;
Jennifer Messerly 2017/01/25 18:31:17 as noted, this change appears to contradict the sp
46 future = $Future.microtask(() => result);
46 } 47 }
47 // Chain the Future so `await` receives the Future's value. 48 // Chain the Future so `await` receives the Future's value.
48 return future.then($dynamic)(onValue, {onError: onError}); 49 return future.then($dynamic)(onValue, {onError: onError});
49 } 50 }
50 return ${getGenericClass(Future)}($T).new(function() { 51 return ${getGenericClass(Future)}($T).microtask(function() {
Jennifer Messerly 2017/01/25 18:31:17 here's the spec for the return value, 16.14 Functi
51 iter = $gen.apply(null, $args)[Symbol.iterator](); 52 iter = $gen.apply(null, $args)[Symbol.iterator]();
52 return onValue(); 53 return onValue();
53 }); 54 });
54 })()'''); 55 })()''');
55 56
56 // Implementation inspired by _AsyncStarStreamController in 57 // Implementation inspired by _AsyncStarStreamController in
57 // dart-lang/sdk's runtime/lib/core_patch.dart 58 // dart-lang/sdk's runtime/lib/core_patch.dart
58 // 59 //
59 // Given input like: 60 // Given input like:
60 // 61 //
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 this.controller.addError(error, stackTrace); 216 this.controller.addError(error, stackTrace);
216 } 217 }
217 } 218 }
218 '''); 219 ''');
219 220
220 /// Returns a Stream of T implemented by an async* function. */ 221 /// Returns a Stream of T implemented by an async* function. */
221 /// 222 ///
222 asyncStar(gen, T, @rest args) => JS('', '''(() => { 223 asyncStar(gen, T, @rest args) => JS('', '''(() => {
223 return new $_AsyncStarStreamController($gen, $T, $args).controller.stream; 224 return new $_AsyncStarStreamController($gen, $T, $args).controller.stream;
224 })()'''); 225 })()''');
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698