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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 87283003: Make the root zone's schduleMicrotask and create[Periodic]Timer bind the callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed tests. 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 part of dart.async; 5 part of dart.async;
6 6
7 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 * ZoneCallback registered = registerBinaryCallback(f); 352 * ZoneCallback registered = registerBinaryCallback(f);
353 * if (runGuarded) { 353 * if (runGuarded) {
354 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg); 354 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg);
355 * } 355 * }
356 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); 356 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2);
357 */ 357 */
358 ZoneBinaryCallback bindBinaryCallback( 358 ZoneBinaryCallback bindBinaryCallback(
359 f(arg1, arg2), { bool runGuarded: true }); 359 f(arg1, arg2), { bool runGuarded: true });
360 360
361 /** 361 /**
362 * Runs [f] asynchronously. 362 * Runs [f] asynchronously in this zone.
363 */ 363 */
364 void scheduleMicrotask(void f()); 364 void scheduleMicrotask(void f());
365 365
366 /** 366 /**
367 * Creates a Timer where the callback is executed in this zone. 367 * Creates a Timer where the callback is executed in this zone.
368 */ 368 */
369 Timer createTimer(Duration duration, void callback()); 369 Timer createTimer(Duration duration, void callback());
370 370
371 /** 371 /**
372 * Creates a periodic Timer where the callback is executed in this zone. 372 * Creates a periodic Timer where the callback is executed in this zone.
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { 725 Zone self, ZoneDelegate parent, Zone zone, f(arg)) {
726 return f; 726 return f;
727 } 727 }
728 728
729 ZoneBinaryCallback _rootRegisterBinaryCallback( 729 ZoneBinaryCallback _rootRegisterBinaryCallback(
730 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) { 730 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) {
731 return f; 731 return f;
732 } 732 }
733 733
734 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { 734 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) {
735 if (Zone.ROOT != zone) {
736 f = zone.bindCallback(f);
737 }
735 _scheduleAsyncCallback(f); 738 _scheduleAsyncCallback(f);
736 } 739 }
737 740
738 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, 741 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone,
739 Duration duration, void callback()) { 742 Duration duration, void callback()) {
743 if (Zone.ROOT != zone) {
744 callback = zone.bindCallback(callback);
745 }
740 return _createTimer(duration, callback); 746 return _createTimer(duration, callback);
741 } 747 }
742 748
743 Timer _rootCreatePeriodicTimer( 749 Timer _rootCreatePeriodicTimer(
744 Zone self, ZoneDelegate parent, Zone zone, 750 Zone self, ZoneDelegate parent, Zone zone,
745 Duration duration, void callback(Timer timer)) { 751 Duration duration, void callback(Timer timer)) {
752 if (Zone.ROOT != zone) {
753 callback = zone.bindUnaryCallback(callback);
754 }
746 return _createPeriodicTimer(duration, callback); 755 return _createPeriodicTimer(duration, callback);
756 }
747 757
748 }
749 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { 758 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) {
750 printToConsole(line); 759 printToConsole(line);
751 } 760 }
752 761
753 void _printToZone(String line) { 762 void _printToZone(String line) {
754 Zone.current.print(line); 763 Zone.current.print(line);
755 } 764 }
756 765
757 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, 766 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone,
758 ZoneSpecification specification, 767 ZoneSpecification specification,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 handleUncaughtError: errorHandler); 917 handleUncaughtError: errorHandler);
909 } 918 }
910 Zone zone = Zone.current.fork(specification: zoneSpecification, 919 Zone zone = Zone.current.fork(specification: zoneSpecification,
911 zoneValues: zoneValues); 920 zoneValues: zoneValues);
912 if (onError != null) { 921 if (onError != null) {
913 return zone.runGuarded(body); 922 return zone.runGuarded(body);
914 } else { 923 } else {
915 return zone.run(body); 924 return zone.run(body);
916 } 925 }
917 } 926 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698