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

Side by Side Diff: tests/lib/async/zone_bind_callback_test.dart

Issue 3014593002: Use generic functions in zones. (Closed)
Patch Set: Added changes missing from patch set #2 Created 3 years, 2 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
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 import 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 main() { 9 main() {
10 Completer done = new Completer(); 10 Completer done = new Completer();
11 11
12 var valueToCapture; 12 var valueToCapture;
13 var restoredValue; 13 var restoredValue;
14 14
15 Expect.identical(Zone.ROOT, Zone.current); 15 Expect.identical(Zone.ROOT, Zone.current);
16 Zone forked = Zone.current.fork(specification: new ZoneSpecification( 16 Zone forked = Zone.current.fork(specification: new ZoneSpecification(
17 registerCallback: (Zone self, ZoneDelegate parent, Zone origin, f()) { 17 registerCallback:
18 <R>(Zone self, ZoneDelegate parent, Zone origin, R f()) {
18 // The zone is still the same as when origin.run was invoked, which 19 // The zone is still the same as when origin.run was invoked, which
19 // is the root zone. (The origin zone hasn't been set yet). 20 // is the root zone. (The origin zone hasn't been set yet).
20 Expect.identical(Zone.current, Zone.ROOT); 21 Expect.identical(Zone.current, Zone.ROOT);
21 // Note that not forwarding is completely legal, though not encouraged. 22 // Note that not forwarding is completely legal, though not encouraged.
22 var capturedValue = valueToCapture; 23 var capturedValue = valueToCapture;
23 return parent.registerCallback(origin, () { 24 return parent.registerCallback(origin, () {
24 restoredValue = capturedValue; 25 restoredValue = capturedValue;
25 return f(); 26 return f();
26 }); 27 });
27 })); 28 }));
28 29
29 valueToCapture = 499; 30 valueToCapture = 499;
30 var fun = () { 31 var fun = () {
31 Expect.identical(forked, Zone.current); 32 Expect.identical(forked, Zone.current);
32 return 99; 33 return 99;
33 }; 34 };
34 var registered = forked.bindCallback(fun, runGuarded: false); 35 var registered = forked.bindCallback(fun);
35 Expect.isFalse(identical(fun, registered)); 36 Expect.isFalse(identical(fun, registered));
36 37
37 var result = registered(); 38 var result = registered();
38 Expect.equals(99, result); 39 Expect.equals(99, result);
39 Expect.equals(499, restoredValue); 40 Expect.equals(499, restoredValue);
40 } 41 }
OLDNEW
« no previous file with comments | « tests/lib/async/stream_listen_zone_test.dart ('k') | tests/lib/async/zone_bind_callback_unary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698