OLD | NEW |
1 dart_library.library('language/async_star_stream_take_test', null, /* Imports */
[ | 1 dart_library.library('language/async_star_stream_take_test', null, /* Imports */
[ |
2 'dart_sdk', | 2 'dart_sdk', |
3 'async_helper', | 3 'async_helper', |
4 'expect' | 4 'expect' |
5 ], function load__async_star_stream_take_test(exports, dart_sdk, async_helper, e
xpect) { | 5 ], function load__async_star_stream_take_test(exports, dart_sdk, async_helper, e
xpect) { |
6 'use strict'; | 6 'use strict'; |
7 const core = dart_sdk.core; | 7 const core = dart_sdk.core; |
8 const async = dart_sdk.async; | 8 const async = dart_sdk.async; |
9 const dart = dart_sdk.dart; | 9 const dart = dart_sdk.dart; |
10 const dartx = dart_sdk.dartx; | 10 const dartx = dart_sdk.dartx; |
11 const async_helper$ = async_helper.async_helper; | 11 const async_helper$ = async_helper.async_helper; |
12 const expect$ = expect.expect; | 12 const expect$ = expect.expect; |
13 const async_star_stream_take_test = Object.create(null); | 13 const async_star_stream_take_test = Object.create(null); |
| 14 let FutureOfint = () => (FutureOfint = dart.constFn(async.Future$(core.int)))(
); |
14 let intToStream = () => (intToStream = dart.constFn(dart.definiteFunctionType(
async.Stream, [core.int])))(); | 15 let intToStream = () => (intToStream = dart.constFn(dart.definiteFunctionType(
async.Stream, [core.int])))(); |
15 let StreamTodynamic = () => (StreamTodynamic = dart.constFn(dart.definiteFunct
ionType(dart.dynamic, [async.Stream])))(); | 16 let StreamToFutureOfint = () => (StreamToFutureOfint = dart.constFn(dart.defin
iteFunctionType(FutureOfint(), [async.Stream])))(); |
16 let dynamicTodynamic = () => (dynamicTodynamic = dart.constFn(dart.definiteFun
ctionType(dart.dynamic, [dart.dynamic])))(); | 17 let intTodynamic = () => (intTodynamic = dart.constFn(dart.definiteFunctionTyp
e(dart.dynamic, [core.int])))(); |
17 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); | 18 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
18 async_star_stream_take_test.makeStream = function(n) { | 19 async_star_stream_take_test.makeStream = function(n) { |
19 return dart.asyncStar(function*(stream, n) { | 20 return dart.asyncStar(function*(stream, n) { |
20 for (let i = 0; i < dart.notNull(n); i++) { | 21 for (let i = 0; i < dart.notNull(n); i++) { |
21 if (stream.add(i)) return; | 22 if (stream.add(i)) return; |
22 yield; | 23 yield; |
23 } | 24 } |
24 }, dart.dynamic, n); | 25 }, dart.dynamic, n); |
25 }; | 26 }; |
26 dart.fn(async_star_stream_take_test.makeStream, intToStream()); | 27 dart.fn(async_star_stream_take_test.makeStream, intToStream()); |
27 async_star_stream_take_test.main = function() { | 28 async_star_stream_take_test.main = function() { |
28 function f(s) { | 29 function f(s) { |
29 return dart.async(function*(s) { | 30 return dart.async(function*(s) { |
30 let r = 0; | 31 let r = 0; |
31 let it = async.StreamIterator.new(s.take(5)); | 32 let it = async.StreamIterator.new(s.take(5)); |
32 try { | 33 try { |
33 while (yield it.moveNext()) { | 34 while (yield it.moveNext()) { |
34 let v = it.current; | 35 let v = it.current; |
35 r = dart.notNull(r) + dart.notNull(core.int._check(v)); | 36 r = dart.notNull(r) + dart.notNull(core.int._check(v)); |
36 } | 37 } |
37 } finally { | 38 } finally { |
38 yield it.cancel(); | 39 yield it.cancel(); |
39 } | 40 } |
40 return r; | 41 return r; |
41 }, dart.dynamic, s); | 42 }, core.int, s); |
42 } | 43 } |
43 dart.fn(f, StreamTodynamic()); | 44 dart.fn(f, StreamToFutureOfint()); |
44 async_helper$.asyncStart(); | 45 async_helper$.asyncStart(); |
45 dart.dsend(f(async_star_stream_take_test.makeStream(10)), 'then', dart.fn(v
=> { | 46 f(async_star_stream_take_test.makeStream(10)).then(dart.dynamic)(dart.fn(v =
> { |
46 expect$.Expect.equals(10, v); | 47 expect$.Expect.equals(10, v); |
47 async_helper$.asyncEnd(); | 48 async_helper$.asyncEnd(); |
48 }, dynamicTodynamic())); | 49 }, intTodynamic())); |
49 }; | 50 }; |
50 dart.fn(async_star_stream_take_test.main, VoidTodynamic()); | 51 dart.fn(async_star_stream_take_test.main, VoidTodynamic()); |
51 // Exports: | 52 // Exports: |
52 exports.async_star_stream_take_test = async_star_stream_take_test; | 53 exports.async_star_stream_take_test = async_star_stream_take_test; |
53 }); | 54 }); |
OLD | NEW |